2017-06-05 81 views
0

我有以下配置彈簧啓動應用程序:春天引導JPA沒有找到數據源

應用

@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class, 
     DataSourceAutoConfiguration.class,JpaRepositoriesAutoConfiguration.class}) 
public class Application extends SpringBootServletInitializer { 

主要配置類:

@Configuration 
@ComponentScan("com.mycompany.it") 
@Import(DatabaseConfiguration.class) 
public class Configuration extends WebMvcConfigurationSupport { 

數據庫配置:

@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 { 

隨着數據源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; 
    } 

然而,當我啓動的應用程序,我得到以下錯誤:

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; 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. Dependency annotations: {}

這裏從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" 

春季啓動版本1.5.3

+0

請問您可以發佈項目的依賴關係,並添加了數據庫連接器依賴關係 –

+0

爲什麼從彈簧自動加載器中排除DataSourceAutoConfiguration.class? – emeraldjava

+0

我們有一個不檢查源代碼密碼的策略,並且由於多個項目共享同一個tomcat實例,所以我們不能只在tomcat環境設置中使用spring.jdbc.password屬性 – user439407

回答

0

檢查錯誤日誌

1 bean which qualifies as autowire candidate. Dependency annotations

似乎在配置bean時出現錯誤。