【问题标题】:Spring singletons is instantiated before JNDI DataSourceBinding occured在 JNDI DataSourceBinding 发生之前实例化 Spring 单例
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    相关资源
    最近更新 更多