最近刚开始学习srpringboot,在集成mysql和jpa的时候启动springboot遇到了下面的问题:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-05-31 08:37:45.470 ERROR 9052 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration required a bean of type 'javax.sql.DataSource' that could not be found.
- Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.jndi-name) did not find property 'jndi-name'
- Bean method 'dataSource' not loaded because @ConditionalOnBean (types: org.springframework.boot.jta.XADataSourceWrapper; SearchStrategy: all) did not find any beans
Action:
Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.
看了网上的添加@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})解决方法都没有用,最后看自己的pom文件发现是在做整合jdbc的时候添加了
<dependency>
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId>
<scope>test</scope>
</dependency>
整合jpa的时候又添加了
<dependency>
<groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
和
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
感觉是“mysql-connector-java”和“spring-boot-starter-jdbc”有冲突,就把“spring-boot-starter-jdbc”的引入给删除了,随后启动就OK了。
对于初学者,处处是坑啊!