如何解决@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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。