Java Spring Boot JPA找不到数据源
我有一个具有以下配置的spring引导应用程序:Java Spring Boot JPA找不到数据源,java,spring,spring-boot,spring-data-jpa,Java,Spring,Spring Boot,Spring Data Jpa,我有一个具有以下配置的spring引导应用程序: @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 @Ena
@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 {
应用
@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 {
使用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;
}
但是,当我启动应用程序时,会出现以下错误:
原因:
org.springframework.beans.factory.unsatifiedDependencyException:
创建名为的bean时出错
'org.springframework.boot.autoconfigure.orm.jpa.hibernatejpaaautoconfiguration':
通过构造函数参数0表示的未满足依赖关系;
嵌套异常是
org.springframework.beans.factory.noSuchBean定义异常:否
“javax.sql.DataSource”类型的合格bean可用:应在
至少1个符合autowire候选资格的bean。附属国
注释:{}
以下是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版本1.5.3检查错误日志
1个符合autowire候选资格的bean。依赖项注释
配置bean时似乎出现了错误。能否发布项目的依赖项并添加数据库连接器依赖项?为什么要从spring自动加载程序中排除DataSourceAutoConfiguration.class?我们有一个不将密码签入源代码的策略,由于多个项目共享同一个tomcat实例,我们不能在tomcat环境设置中只使用spring.jdbc.password属性