Spring JNDI,如何告诉容器没有代码的bean在哪里?

时间:2015-08-03 21:55:39

标签: java spring jetty jndi

我已经要求对旧的Spring应用程序进行增强(我认为2.0但可能是2.5)并且我对Spring知之甚少。该应用程序在Oracle OC4J下运行,因为它是给我的,我试图让它在Jetty下运行,所以我可以调试它。我从pom.xml将项目导入最新的Spring Tool Suite并修复了一些似乎是一些小的配置问题,我认为它将在我正在使用的Spring 4下运行。我能够使用mvn来构建一个WAR文件,现在我试图让它在Jetty下运行。

当我启动它时,Jetty运行器会抛出一些异常,例如下面我粘贴的那个,但是常见的主题似乎是它无法解析我的bean。我找到了一些帖子,展示了如何在代码中添加命名信息,但是这段代码已经按原样运行,并且需要在我更改它之后在现在运行的相同环境下运行。所以我犹豫要做出那样的改变。似乎我可以以某种方式将其映射到属性文件中,但我找不到这样做的方法。

我认为以下例外的重要信息是:

Invocation of init method failed; nested exception is javax.naming.NameNotFoundException; remaining name 'datasource/regcntrllst'

如果有人可以告诉我哪些错误并指出了相应的文档,我将非常感谢,谢谢...

这是来自src / main / resources / edu的XML配置文件,名为applicationContext-container.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!-- 
    Provides bean definitions for use in the J2EE container (as opposed to in the standalone test
    environment. 
-->

    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
    <!-- Data Sources -->
    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  -->

    <bean id="sisDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="datasource/regcntrllst" />
        <property name="resourceRef" value="true" />        
    </bean>

    <!--  Transaction manager outside of app servers -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

</beans>

以下是例外:

VJG8WP:jetty-test jarcher$ java -cp jetty-runner-9.3.2.v20150730.jar org.eclipse.jetty.runner.Runner academic-regcntrllst-1.2.10-SNAPSHOT.war 
2015-08-03 16:49:17.344:INFO::main: Logging initialized @105ms
2015-08-03 16:49:17.351:INFO:oejr.Runner:main: Runner
2015-08-03 16:49:17.433:INFO:oejs.Server:main: jetty-9.3.2.v20150730
2015-08-03 16:49:21.943:INFO:/:main: No Spring WebApplicationInitializer types detected on classpath
2015-08-03 16:49:22.093:INFO:/:main: Initializing Spring root WebApplicationContext
[ERROR] [2015-08-03 16:49:23,575] [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mitsisStudentService' defined in URL [jar:file:/private/var/folders/z5/m0w5k8z16xq25l_26n_fsl1m0000gn/T/jetty-0.0.0.0-8080-academic-regcntrllst-1.2.10-SNAPSHOT.war-_-any-4602767227392286160.dir/webapp/WEB-INF/lib/csf-common-legacy-2.0.43.jar!/applicationContext-csf-common.xml]: Cannot resolve reference to bean 'hibernateStudentDao' while setting bean property 'studentDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateStudentDao' defined in URL [jar:file:/private/var/folders/z5/m0w5k8z16xq25l_26n_fsl1m0000gn/T/jetty-0.0.0.0-8080-academic-regcntrllst-1.2.10-SNAPSHOT.war-_-any-4602767227392286160.dir/webapp/WEB-INF/lib/csf-common-legacy-2.0.43.jar!/applicationContext-csf-common.xml]: Cannot resolve reference to bean 'daoFoundation' while setting bean property 'daoFoundation'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoFoundation' defined in URL [jar:file:/private/var/folders/z5/m0w5k8z16xq25l_26n_fsl1m0000gn/T/jetty-0.0.0.0-8080-academic-regcntrllst-1.2.10-SNAPSHOT.war-_-any-4602767227392286160.dir/webapp/WEB-INF/lib/csf-orm-2.0.43.jar!/applicationContext-csf-orm-config.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [file:/private/var/folders/z5/m0w5k8z16xq25l_26n_fsl1m0000gn/T/jetty-0.0.0.0-8080-academic-regcntrllst-1.2.10-SNAPSHOT.war-_-any-4602767227392286160.dir/webapp/WEB-INF/classes/applicationContext.xml]: Cannot resolve reference to bean 'mitsisDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mitsisDataSource' defined in URL [file:/private/var/folders/z5/m0w5k8z16xq25l_26n_fsl1m0000gn/T/jetty-0.0.0.0-8080-academic-regcntrllst-1.2.10-SNAPSHOT.war-_-any-4602767227392286160.dir/webapp/WEB-INF/classes/applicationContext-container.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException; remaining name 'datasource/regcntrllst'
    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:1360)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    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$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:771)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1368)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1335)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:735)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:511)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:161)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
    at org.eclipse.jetty.server.Server.start(Server.java:405)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
    at org.eclipse.jetty.server.Server.doStart(Server.java:372)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.runner.Runner.run(Runner.java:502)
    at org.eclipse.jetty.runner.Runner.main(Runner.java:547)

1 个答案:

答案 0 :(得分:0)

看起来无法找到数据源'datasource / regcntrllst'

您需要将此数据源添加到Jetty服务器。这是Jetty文档的Configuring DataSources部分。