我是Java EE的新手,我有一些问题,在绑定JNDI本身之前,实例化了具有JndiObjectFactoryBean属性的spring单例。它会导致部署错误并使应用程序部署失败。
无论如何配置初始化的优先级?比如让JNDI DataSourceBinding在Spring单例之前首先实例化?
我使用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'
如果有人可以帮助我,我真的很感激。 感谢
答案 0 :(得分:0)
最后,由于部署期间的问题,单个JNDI绑定之前实例化单例,由于某种原因,应用程序被部署到属于JBoss的.sar文件夹内。因此,在实例化JNDI之前加载应用程序。 将我的应用程序移动到正确的文件夹后,它正好像以前一样运行。