简体   繁体   English

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

[英]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. 我被要求对一个较旧的Spring应用程序进行增强(我认为是2.0,但也许是2.5),而我对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. 该应用程序按给我的方式在Oracle OC4J下运行,我正在尝试使其在Jetty下运行,以便可以对其进行调试。 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. 我将项目从其pom.xml导入到最新的Spring Tool Suite中,并修复了一些较小的配置问题,并且我认为它将在我使用的Spring 4下运行。 I was able to use mvn to build a WAR file and now I am trying to get it to run under Jetty. 我能够使用mvn生成WAR文件,现在我试图使其在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. 当我启动它时,Jetty运行程序会抛出很多异常,例如我将在下面粘贴的异常,但是常见的主题似乎是它无法解析我的bean。 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 这是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>

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. 似乎找不到数据源“ datasource / regcntrllst”

You need to add this data-source with the same name to your Jetty server. 您需要将此具有相同名称的数据源添加到您的Jetty服务器。 Here's the Configuring DataSources section of the Jetty documentation. 这是Jetty文档的“ 配置数据源”部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何告诉Spring实例化选定的bean,而不提供构造函数args? - How to tell Spring to instantiate selected beans without providing constructor args? 如何告诉visualvm在哪里找到我的源代码? - How do I tell visualvm where to find my source code? 如何从Web容器外部查找JNDI数据源? - How do I lookup a JNDI Datasource from outside a web container? 我在哪里将我的XML bean放在Spring Boot应用程序中? - Where do I put my XML beans in a Spring Boot application? 如何在不使用 bean 或注释的情况下手动初始化 Spring Boot 存储库? (科特林) - How do I manually initialize a Spring Boot repository without using beans or annotations? (Kotlin) 如何在不定义每个 Spring bean 的情况下创建多个相同类型的 Spring bean - How do I create multiple Spring beans of the same type without defining each one Spring项目我如何访问JBoss JNDI数据源 - Spring project how do I access JBoss JNDI Datasources 我如何告诉Maven Tomcat在哪里? - How do I tell maven where is Tomcat? 如何在 Spring boot 控制台应用程序中将 spring bean 注入非托管 bean? - How do I inject spring beans into non-managed beans in a Spring boot console application? 如何修改spring容器中定义的bean - How to modify beans defined in a spring container
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM