[英]Spring Boot JPA not finding data source
I have a spring boot application with the following configuration: 我有一个具有以下配置的spring boot应用程序:
Application 应用
@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class,
DataSourceAutoConfiguration.class,JpaRepositoriesAutoConfiguration.class})
public class Application extends SpringBootServletInitializer {
Main configuration class: 主要配置类:
@Configuration
@ComponentScan("com.mycompany.it")
@Import(DatabaseConfiguration.class)
public class Configuration extends WebMvcConfigurationSupport {
Database configuration: 数据库配置:
@Configuration
@ComponentScan(basePackages = {"com.mycompany.it.xp2.integration.workday.dao","com.mycompany.it.xp2.integration.workday.application","com.company.it.xp2.integration.workday.model"})
@EnableAspectJAutoProxy
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"com.company.it.xp2.integration.workday.dao","com.company.it.xp2.integration.workday.model"})
public class DatabaseConfiguration {
With DataSource bean declaration: 使用DataSource bean声明:
@Bean(destroyMethod = "close")
@Primary
public DataSource dataSource() throws PropertyVetoException {
ComboPooledDataSource source = new ComboPooledDataSource();
source.setDriverClass(driverClass);
source.setJdbcUrl(jdbcUrl);
source.setUser(jdbcUsername);
source.setPassword(jdbcPassword);
source.setInitialPoolSize(initialSize);
source.setMaxPoolSize(maxActive);
source.setMinPoolSize(minIdle);
return source;
}
However when I start up the application I get the following error: 但是,当我启动应用程序时,出现以下错误:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; 由以下原因引起:org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration”的bean时出错:通过构造函数参数0表示的不满意依赖关系; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.sql.DataSource' available: expected at least 1 bean which qualifies as autowire candidate. 嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的'javax.sql.DataSource'类型的合格Bean:至少应有1个可以作为自动装配候选的Bean。 Dependency annotations: {} 依赖注释:{}
Here are the related lines from gradle: 这是gradle的相关代码:
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
compile group: 'org.springframework', name: 'spring-orm'
compile group: "org.springframework.boot", name: "spring-boot-starter-jdbc"
compile "org.springframework.boot:spring-boot-starter-data-jpa"
Spring boot version 1.5.3 春季启动版本1.5.3
Check the error log 检查错误日志
1 bean which qualifies as autowire candidate. 1个符合自动装配候选条件的bean。 Dependency annotations 依赖注释
It seems that there is an error when you configured the bean. 配置bean时似乎出现错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.