BeanCreationException:使用名称创建 bean 时出错:注入自动装配的依赖项失败;

BeanCreationException: Error creating bean with name: Injection of autowired dependencies failed;

我在尝试使用我编写的码头服务器部署 war 时收到以下错误堆栈。

INFO : jetty.StartJetty - starting jetty using war file ..\serialisation-preview-service\target\serialisation-preview-service-1.3.0-SNAPSHOT.war
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/username/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/username/.m2/repository/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
INFO : org.eclipse.jetty.util.log - jetty-7.2.2.v20101205
INFO : org.eclipse.jetty.util.log - Extract jar:file:/U:/Code/Serialisation_Fresh/serialisation-preview-service/target/serialisation-preview-service-1.3.0-SNAPSHOT.war!/ to C:\Users\username\AppData\Local\Temp\jetty-0.0.0.0-8080-serialisation-preview-service-1.3.0-SNAPSHOT.war-_-any-\webapp
INFO : / - Initializing Spring root WebApplicationContext
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing Root WebApplicationContext: startup date [Fri May 22 09:02:37 BST 2015]; root of context hierarchy
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@d75e99: defining beans []; root of factory hierarchy
INFO : org.springframework.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 1958 ms
WARN : org.eclipse.jetty.util.log - FAILED jsp: java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
INFO : / - Initializing Spring FrameworkServlet 'appServlet'
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization started
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Refreshing WebApplicationContext for namespace 'appServlet-servlet': startup date [Fri May 22 09:02:39 BST 2015]; parent: Root WebApplicationContext
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from ServletContext resource [/WEB-INF/servlet-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [preview-service-context.xml]
INFO : org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [dao-context.xml]
INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from class path resource [placeit.properties]
INFO : org.springframework.beans.factory.config.PropertyOverrideConfigurer - Loading properties file from class path resource [preview-server-overrideDEV.properties]
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@d61b48: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,myController,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,previewServerPropertyOverride,org.springframework.beans.factory.config.PropertyOverrideConfigurer#0,labelService,placeit.SerialDataCSVGenerator#0,placeit.DataMatrixGenerator#0,org.springframework.expression.spel.standard.SpelExpressionParser#0,printers,ftp.FtpEmulator#0,placeitPreviewProcess,placeitLabelProcess,placeitHapaProcess,hgdlCompiler,util.DateServiceImpl#0,org.springframework.integration.internalDefaultConfiguringBeanFactoryPostProcessor,org.springframework.scheduling.support.PeriodicTrigger#0,poller,JobFileCreator,rendezvous,PreviewService,org.springframework.integration.transformer.HeaderEnricher#0,org.springframework.integration.transformer.MessageTransformingHandler#0,writeFiles,org.springframework.integration.config.ConsumerEndpointFactoryBean#0,writeFiles2,limitJobs,org.springframework.integration.router.RecipientListRouter#0,writeJobRouter,org.springframework.integration.config.ServiceActivatorFactoryBean#0,createJobFile,createJobFileSA,org.springframework.integration.transformer.HeaderEnricher#1,org.springframework.integration.transformer.MessageTransformingHandler#1,writeJobFile,org.springframework.integration.config.ConsumerEndpointFactoryBean#1,writeJobFile2,org.springframework.integration.file.config.FileWritingMessageHandlerFactoryBean#0,writeJobFile2.adapter,org.springframework.integration.transformer.HeaderEnricher#2,org.springframework.integration.transformer.MessageTransformingHandler#2,writeFmtFile,org.springframework.integration.config.ConsumerEndpointFactoryBean#2,writeFmtFile2,org.springframework.integration.file.config.FileWritingMessageHandlerFactoryBean#1,writeFmtFile2.adapter,org.springframework.integration.config.ServiceActivatorFactoryBean#1,waitForReply,org.springframework.integration.config.ConsumerEndpointFactoryBean#3,generatedPreviewFile,org.springframework.integration.file.config.FileListFilterFactoryBean#0,org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean#0,generatedPreviewFile.adapter,org.springframework.integration.config.TransformerFactoryBean#0,org.springframework.integration.config.ConsumerEndpointFactoryBean#4,org.springframework.integration.config.ServiceActivatorFactoryBean#2,deliverReply,org.springframework.integration.config.ConsumerEndpointFactoryBean#5,aggregationDaoImpl,notificationDaoImpl,parametersDaoImpl,serialisationDaoImpl,templatePreviewDaoImpl,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,entityManagerFactory,org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.simple.SimpleJdbcTemplate#0,dataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,nullChannel,errorChannel,_org.springframework.integration.errorLogger,taskScheduler]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@d75e99
INFO : org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler - Initializing ExecutorService  'taskScheduler'
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@d61b48: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,myController,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,previewServerPropertyOverride,org.springframework.beans.factory.config.PropertyOverrideConfigurer#0,labelService,placeit.SerialDataCSVGenerator#0,placeit.DataMatrixGenerator#0,org.springframework.expression.spel.standard.SpelExpressionParser#0,printers,ftp.FtpEmulator#0,placeitPreviewProcess,placeitLabelProcess,placeitHapaProcess,hgdlCompiler,util.DateServiceImpl#0,org.springframework.integration.internalDefaultConfiguringBeanFactoryPostProcessor,org.springframework.scheduling.support.PeriodicTrigger#0,poller,JobFileCreator,rendezvous,PreviewService,org.springframework.integration.transformer.HeaderEnricher#0,org.springframework.integration.transformer.MessageTransformingHandler#0,writeFiles,org.springframework.integration.config.ConsumerEndpointFactoryBean#0,writeFiles2,limitJobs,org.springframework.integration.router.RecipientListRouter#0,writeJobRouter,org.springframework.integration.config.ServiceActivatorFactoryBean#0,createJobFile,createJobFileSA,org.springframework.integration.transformer.HeaderEnricher#1,org.springframework.integration.transformer.MessageTransformingHandler#1,writeJobFile,org.springframework.integration.config.ConsumerEndpointFactoryBean#1,writeJobFile2,org.springframework.integration.file.config.FileWritingMessageHandlerFactoryBean#0,writeJobFile2.adapter,org.springframework.integration.transformer.HeaderEnricher#2,org.springframework.integration.transformer.MessageTransformingHandler#2,writeFmtFile,org.springframework.integration.config.ConsumerEndpointFactoryBean#2,writeFmtFile2,org.springframework.integration.file.config.FileWritingMessageHandlerFactoryBean#1,writeFmtFile2.adapter,org.springframework.integration.config.ServiceActivatorFactoryBean#1,waitForReply,org.springframework.integration.config.ConsumerEndpointFactoryBean#3,generatedPreviewFile,org.springframework.integration.file.config.FileListFilterFactoryBean#0,org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean#0,generatedPreviewFile.adapter,org.springframework.integration.config.TransformerFactoryBean#0,org.springframework.integration.config.ConsumerEndpointFactoryBean#4,org.springframework.integration.config.ServiceActivatorFactoryBean#2,deliverReply,org.springframework.integration.config.ConsumerEndpointFactoryBean#5,aggregationDaoImpl,notificationDaoImpl,parametersDaoImpl,serialisationDaoImpl,templatePreviewDaoImpl,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,entityManagerFactory,org.springframework.jdbc.core.JdbcTemplate#0,org.springframework.jdbc.core.simple.SimpleJdbcTemplate#0,dataSource,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0,nullChannel,errorChannel,_org.springframework.integration.errorLogger,taskScheduler]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@d75e99
INFO : org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler - Shutting down ExecutorService 'taskScheduler'
ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dao.TemplatePreviewDao controllers.PreviewHttpController.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'templatePreviewDaoImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [dao-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:609)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:571)
    at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:623)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:491)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:432)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:432)
    at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:260)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:762)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:244)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1181)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:584)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:496)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:226)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:93)
    at org.eclipse.jetty.server.Server.doStart(Server.java:243)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at jetty.StartJetty.main(StartJetty.java:56)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private dao.TemplatePreviewDao controllers.PreviewHttpController.dao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'templatePreviewDaoImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [dao-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:504)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
    ... 32 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'templatePreviewDaoImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [dao-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:343)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:476)
    ... 34 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [dao-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:531)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:497)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:658)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:631)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:147)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:340)
    ... 45 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [dao-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    ... 61 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'password' of bean class [org.springframework.jndi.JndiObjectFactoryBean]: Bean property 'password' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1031)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358)
    ... 69 more

这是它抱怨 EntityManager 定义的 TemplatePreview class:

@Repository
public class TemplatePreviewDaoImpl implements TemplatePreviewDao {
    @PersistenceContext private EntityManager entityManager;
    // ...
}

这是我的带有 bean 声明的项目上下文文件之一:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/>

    <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceXmlLocation" value="classpath:/META-INF/persistenceOracle.xml"/>
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>
        </property>
    </bean>

    <bean class="org.springframework.jdbc.core.JdbcTemplate">
    <constructor-arg ref="dataSource"/>
    </bean>

    <bean class="org.springframework.jdbc.core.simple.SimpleJdbcTemplate">
    <constructor-arg ref="dataSource"/>
    </bean>

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
        <property name="jndiName" value="java:comp/env/DS_SERIALISATION"/>
    </bean>

以及包含数据源信息的属性文件的内容:

dataSource.url=jdbc:oracle:thin:@correct_url
dataSource.username=************
dataSource.password=************
dataSource.driverClassName=oracle.jdbc.OracleDriver
entityManagerFactory.persistenceXmlLocation=classpath:/META-INF/persistenceOracle.xml
rendezvous.timeout=-1

这里提到的 persistenceOracle xml 文件也可以访问,所以我认为这不是问题。我不知道为什么 Spring 不能自动装配依赖关系或者为什么我的数据源有问题。如有任何帮助,我们将不胜感激。

编辑

我的覆盖文件存在于一个单独的项目中,但我不能确定我的 war 项目知道它。包含属性文件的项目没有 src 文件夹或任何东西,所以我无法将它添加到 war 项目的 class 路径。

我在我的 运行 配置中将 DEV 作为 VM 参数传递,它在查找正确的属性文件时被附加。

我的想法是,您的数据源只是实例化一个 JndiObjectFactoryBean 类型的对象,然后将其传递到整个地方,直到 Spring 行的某处尝试注入 属性 "password",它发现 JndiObjectFactoryBean 对象没有 属性 "password"。

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" >
        <property name="jndiName" value="java:comp/env/DS_SERIALISATION"/>
</bean>

JNDI 是一个 api,它允许您通过名称访问目录(请参阅教程 here)。它应该根据您提供的 jndiName 执行 JNDI 查找,而不是 returning JndiObjectFactoryBean 对象。

我认为您需要告诉 JndiObjectFactoryBean 进行查找并将 return JNDI 结果作为您的 Spring Bean。考虑以下示例。

Spring配置:

<bean id="jndiLookup" class="org.springframework.jndi.JndiObjectLocator">
    <property name="jndiName" value="java:comp/env/DS_SERIALISATION"/>
</bean>

<bean id="dataSource" class="com.mypackage.DataSourceLocator">
    <property name="jndi" ref="jndiLookup"/>
</bean>

自定义静态工厂以从 jndi 查找中获取对象:

public class DataSourceLocator {

    public JndiObjectLocator jndi;

    public static Object lookup() {
        return jndi.lookup();
    }

}

可能有更好的方法,但我不是 jndi 专家!

在尝试了很多事情之后我决定试试这个:

<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:mem:"/>  
    <property name="username" value="sa"/>
    <property name="password" value=""/>
    <property name="testOnBorrow" value="true"/>
    <property name="testWhileIdle" value="true"/>
    <property name="timeBetweenEvictionRunsMillis" value="300000"/>

似乎可以解决问题。不确定为什么 Jndi 不起作用:S