异常一:Caused by: java.lang.IllegalArgumentException: Not a managed type: class xxx
出现异常的原因及解决办法:
1,实体类没有添加@Entity:解决办法在对应的实体类上添加@Entity
2,实体中@Entity、@Table、@Id引入类型错误 正确引入:import javax.persistence.*;
3,没有默认按照springboot的默认扫描方式,默认扫描(application.java入口类的相对的兄弟包和及其子包)
(1)将实体bean和JpaRepository放在同一个package中
(2)启动类添加
@ComponentScan(basePackages = “com.boot.demo.xxx..”) 用于扫描@Controller @Service
@EnableJpaRepositories(basePackages = “com.boot.demo.xxx..dao") 用于扫描Dao @Repository
@EntityScan("com.boot.demo.xxx..*”) 用于扫描JPA实体类 @Entity
异常二:"could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarExcep。。。。
错误原因:数据库存的和实体类写的不一致
异常三
加上配置
@Configuration
public class DataSourceConfig {
@Bean(name = "dataSource1")
@Qualifier("dataSource1")
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource1() {
return DataSourceBuilder.create().build();
}
}
查看导入jar包版本,尝试删除指定版本号
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--mysql依赖-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>