简体   繁体   中英

Spring JNDI, How do I tell the container where the beans are without code?

I have ben asked to make an enhancement to an older Spring application (I think 2.0 but maybe 2.5) and I know very little about Spring. The application runs under Oracle OC4J as it was given to me, and I am trying to get it to run under Jetty so I can debug it. I imported the project into the latest Spring Tool Suite from its pom.xml and fixed what seemed to be a few minor config issues, and I think it will run under the Spring 4 I am using. I was able to use mvn to build a WAR file and now I am trying to get it to run under Jetty.

When I start it, Jetty runner throws a bunch of exceptions like the one I'll paste below, but the common theme seems to be that it can not resolve my beans. I have found some posts showing how to add naming information into the code, but this code already runs as is and needs to run under the same environment it is running under now after I change it. So I am hesitant to make a change like that. It seems that I could somehow map this in a properties file, but I can't find a way to do that.

I think the important info from the exception below is:

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

If someone could tell me what's wrong and point me to the appropriate docs I would greatly appreciate it, thanks...

Here is an XML configuration file from src/main/resources/edu called 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>

Here is the exception:

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)

It looks like the data-source 'datasource/regcntrllst' can't be found.

You need to add this data-source with the same name to your Jetty server. Here's the Configuring DataSources section of the Jetty documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM