Java Spring单例在发生JNDI DataSourceBinding之前实例化

Java Spring单例在发生JNDI DataSourceBinding之前实例化,java,spring,spring-mvc,datasource,jndi,Java,Spring,Spring Mvc,Datasource,Jndi,我是JavaEE的新手,我有一些问题,在绑定JNDI之前实例化了具有JndiObjectFactoryBean属性的spring单例。它会导致部署错误,并使应用程序部署失败 是否仍然需要配置初始化的优先级?比如在spring单例之前先实例化JNDI DataSourceBinding 我使用jboss-5.1.0.GA作为我的应用服务器 以下是server.log的片段: 2015-05-25 16:47:14,410 INFO [org.springframework.beans.facto

我是JavaEE的新手,我有一些问题,在绑定JNDI之前实例化了具有JndiObjectFactoryBean属性的spring单例。它会导致部署错误,并使应用程序部署失败

是否仍然需要配置初始化的优先级?比如在spring单例之前先实例化JNDI DataSourceBinding

我使用jboss-5.1.0.GA作为我的应用服务器

以下是server.log的片段:

2015-05-25 16:47:14,410 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (main) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1f873f7: defining beans [daoAuthenticationProvider,authenticationManager,settingbean,authenticationFailureHandler,authenticationSuccessHandler,sessionRegistry,sessionAuthenticationStrategy,authenticationFilter,sessionManageProcessingFilter,httpSessionContextIntegrationFilter,filterChainProxy,securityContextPersistenceFilter,filterSecurityInterceptor,httpRequestAccessDecisionManager,roleVoter,cxcdataDS,datasourceByJNDI,JTATransactionManager,jdbcTXManager,jdbcTemplate,jdbcTemplateext]; root of factory hierarchy
2015-05-25 16:47:14,593 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (main) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1f873f7: defining beans [daoAuthenticationProvider,authenticationManager,settingbean,authenticationFailureHandler,authenticationSuccessHandler,sessionRegistry,sessionAuthenticationStrategy,authenticationFilter,sessionManageProcessingFilter,httpSessionContextIntegrationFilter,filterChainProxy,securityContextPersistenceFilter,filterSecurityInterceptor,httpRequestAccessDecisionManager,roleVoter,cxcdataDS,datasourceByJNDI,JTATransactionManager,jdbcTXManager,jdbcTemplate,jdbcTemplateext]; root of factory hierarchy
2015-05-25 16:47:14,593 ERROR [org.springframework.web.context.ContextLoader] (main) Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoAuthenticationProvider' defined in ServletContext resource [/WEB-INF/classes/CXC_Security.xml]: Cannot create inner bean 'org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl#1437781' of type [org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl] while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl#1437781' defined in ServletContext resource [/WEB-INF/classes/CXC_Security.xml]: Cannot resolve reference to bean 'cxcdataDS' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cxcdataDS' defined in ServletContext resource [/WEB-INF/classes/CXC_DataSource.xml]: Cannot resolve reference to bean 'datasourceByJNDI' while setting bean property 'targetDataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'datasourceByJNDI' defined in ServletContext resource [/WEB-INF/classes/CXC_DataSource.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: cxcdataDS not bound
...
只有在长堆栈跟踪错误之后,才会实例化所需的JNDI绑定

2015-05-25 16:47:16,759 INFO  [org.jboss.resource.connectionmanager.ConnectionFactoryBindingService] (main) Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=cxcdataDS' to JNDI name 'java:cxcdataDS'
如果有人能帮我,我会非常感激的。
谢谢

最后,由于部署过程中的问题,在绑定JNDI之前,单例被实例化,出于某种原因,应用程序被部署到JBoss的.sar文件夹中。因此,在实例化JNDI之前加载应用程序。
在我将应用程序移动到正确的文件夹后,它会像以前一样正常运行。

我不确定,但是,您是否尝试在您的CXC\u Security.xml中使用as-JNDI名称java:cxcdataDS而不是cxcdataDS?Hi@Vartlok,感谢您的帮助。幸运的是,我找到了问题的原因。JNDI命名本身没有问题,只是部署问题。