@Entitty和@EntityScan不起作用我正在使用Spring Boot和JPA存储库,发生了很多次

问题描述

我正在使用spring boot和jpa存储库,但是@Entity和@EntityScan不起作用。日志和主要代码在这里

@SpringBootApplication
@EntityScan(basePackages = {"com.demo.detail"})
@EnableJpaRepositories(basePackages = {"com.demo.detail"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }
}

实体在这里定义

@Entity
@EqualsAndHashCode(callSuper = true)
@DynamicUpdate
@Data
public class BizDO extends BaseDO {
    @Id
    private Long id;
    private String bizKey;
    private String links;
    private String description;
    private Integer status;
    private String creator;
}

此处定义存储库

public interface BizRepository extends JpaRepository<BizDO,Long> {
}

解决方法

我在这里编写了类BizDO和与jpa相关的配置

# application.properties
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

和此处的bean.xml

    <bean id="entityManagerFactory"
       class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="packagesToScan" value="org.wahid.cse.entity"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            </props>
        </property>
        <property name="persistenceProvider">
            <bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean>
        </property>
    </bean>