spring data jpa 出现Not a managed type

         这几天看自己买的那本spring boot的书,学些spring boot,spring boot零配置还是挺好用的,当看到spring data jpa时,我想自己写一下,spring data jpa 还是挺好用的,其中的那个写jpa对应的dao层,只需要extends JpaRepository<实体, 实体对应的主键>,然后在接口上用@Query写对应的hql语句,这点我觉得快赶上mybatis的灵活性了,在其他层注入的时候发现注入不进去,经自己一中午的查资料和实践发现,spring data jpa 由于我用的是spring boot,所以我只说spring boot中的解决。需要在配置类的上面加上@EnableJpaRepositories(basePackages={"dao层对应的包路径"}),这样jpa的dao层就注入进来了。结果启动spring boot 时发现,又有 Not a managed type: class ******的错误,经查询发现少了jpa entity路径的配置,在配置类的头部加上标记:@EntityScan("entity对应的包路径")。对于spring boot 使用jpa,需要在目录下加上application.properties文件,如果是maven项目在resource目录下,里面是jpa的一些数据的配置例如:下面是我的配置

spring.datasource.url = jdbc:mysql://IP:port/库
spring.datasource.username = 用户名
spring.datasource.password = 密码
spring.datasource.driverClassName = com.mysql.jdbc.Driver
# Specify the DBMS
spring.jpa.database = MYSQL
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy


# stripped before adding them to the entity manager)
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值