最近在项目组整理一个Spring boot的二次开发。启动总是报错,确定配置文件pom.xml、application.properties等等都没有问题!由于网上相关问题都没有找到解决方法,记录下。
#application.properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/……
spring.datasource.username=……
spring.datasource.password=……
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=false
spring.jackson.serialization.indent_output=true
#pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
整了很久,也查了资料,无果,报错如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.3.RELEASE)
***************************
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: 漏了拷贝,汗) did not find any beans
Action:
Consider revisiting the conditions above or defining a bean of type 'javax.sql.DataSource' in your configuration.
后来只能搭个简单项目,从0开始运行试下,发现是maven下的包有问题,需要重新下载(项目没有报错,依赖的jar包都有存在,但是删除后重新下载,发现jar包的大小其实是不一样,傻眼)。
解决办法:
重新下载相关的依赖jar包。
删除Maven的依赖Jar文件目录,…/.m2/repository/org/springframework目录都删除。然后项目重新install下载依赖包,运行,成功!