Spring 无法自动连接字段:private javax.sql.DataSource

Spring 无法自动连接字段:private javax.sql.DataSource,spring,spring-boot,Spring,Spring Boot,我有一个简单的基于jpa的spring boot项目 @EnableJpaRepositories(basePackages=“de.dahilein.resourcecal.repos”) @配置 @组件扫描 @EnableAutoConfiguration(排除={DataSourceAutoConfiguration.class}) 公共类资源应用程序{ 公共静态void main(字符串[]args){ run(ResourceCalApplication.class,args); }

我有一个简单的基于jpa的spring boot项目

@EnableJpaRepositories(basePackages=“de.dahilein.resourcecal.repos”)
@配置
@组件扫描
@EnableAutoConfiguration(排除={DataSourceAutoConfiguration.class})
公共类资源应用程序{
公共静态void main(字符串[]args){
run(ResourceCalApplication.class,args);
}
@豆子
公共LocalEntityManagerFactoryBean entityManagerFactory(){
EntityManagerFactory emf=Persistence.createEntityManagerFactory(“resourcecal”);
返回电动势;
}
@豆子
公共平台transactionManager transactionManager(){
JpaTransactionManager transactionManager=新的JpaTransactionManager();
setEntityManagerFactory(entityManagerFactory());
返回事务管理器;
}
}
我得到以下堆栈跟踪

01:16:50.072[localhost-startStop-1]错误o.s.web.context.ContextLoader-上下文初始化失败
org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.boot.autoconfigure.orm.jpa.hibernateJPA自动配置”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接字段:private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.DataSource;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖项类型为[javax.sql.DataSource]的符合条件的bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
在org.springframework.beans.factory.annotation.AutowiredNotationBeanPostProcessor.postProcessPropertyValues(AutowiredNotationBeanPostProcessor.java:334)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.beans.factory.support.DefaultListableBeanFactory.PreInstanceSingleton(DefaultListableBeanFactory.java:772)~[spring-beans-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)~[spring-context-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4810)[catalina.jar:8.0.30]
在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)[catalina.jar:8.0.30]
在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)[catalina.jar:8.0.30]
在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)[catalina.jar:8.0.30]
在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)[catalina.jar:8.0.30]
在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)[catalina.jar:8.0.30]
在org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:945)[catalina.jar:8.0.30]
在org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1795)[catalina.jar:8.0.30]
在java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[na:1.8.0]
在java.util.concurrent.FutureTask.run(FutureTask.java:266)[na:1.8.0]
位于java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[na:1.8.0]
位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[na:1.8.0]
在java.lang.Thread.run(Thread.java:744)[na:1.8.0]
原因:org.springframework.beans.factory.BeanCreationException:无法自动连接字段:private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.DataSource;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:未找到依赖项类型为[javax.sql.DataSource]的符合条件的bean:应至少1个bean
@Bean
public DataSource dataSource() {
    final JndiDataSourceLookup jndiDataSource= new JndiDataSourceLookup();
    jndiDataSource.setResourceRef(true);
    DataSource dataSource = jndiDataSource.getDataSource("jdbc/resourcecalDS");
    return dataSource;
}
<version>2.0.5.RELEASE</version>