【发布时间】:2015-05-25 11:45:03
【问题描述】:
我是 Java EE 的新手,我遇到了一些问题,即在绑定 JNDI 本身之前实例化具有 JndiObjectFactoryBean 属性的弹簧单例。导致部署出错,导致应用部署失败。
有没有配置初始化的优先级?比如让JNDI DataSourceBinding在spring singletons之前先实例化?
我使用 jboss-5.1.0.GA 作为我的应用服务器。
这里是server.log的sn-p:
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'
如果有人可以为此提供帮助,我将不胜感激。 谢谢
【问题讨论】:
-
我不确定,但是您是否尝试过在您的
CXC_Security.xml中使用java:cxcdataDS而不是cxcdataDS作为JNDI 名称? -
嗨@Vartlok,感谢您提供帮助。幸运的是,我找到了问题的原因。 JNDI命名本身没有问题,只是部署问题。
标签: java spring spring-mvc datasource jndi