這個web應用程序在我的本地主機碼頭服務器上工作得很好。我正在Jelastic上進行測試,以便在部署到生產服務器之前解決任何問題。Spring應用程序上下文問題 - 數據源Bean創建
問題是,應用程序無法啓動,因爲配置錯誤,我無法修復,你能幫我嗎?對於這個問題
完全堆棧跟蹤:
[ERROR] ioc.Registry Operations trace:
[ERROR] ioc.Registry [ 1] Realizing service ApplicationContext
[ERROR] ioc.Registry [ 2] Instantiating service ApplicationContext implementation via ObjectCreator for Spring ApplicationContext
[ERROR] ioc.Registry [ 3] Creating Spring ApplicationContext via ContextLoader
[ERROR] SpringModuleDef.ApplicationContext Construction of service ApplicationContext failed: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException; remaining name 'jdbc/appDB'
org.apache.tapestry5.ioc.internal.OperationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException; remaining name 'jdbc/appDB'
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
at org.apache.tapestry5.internal.spring.SpringModuleDef$3.createObject(SpringModuleDef.java:184)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
at org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
at org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63)
at org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54)
at org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:66)
at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:54)
at $ConfigurableWebApplicationContext_38b45053c6a2.delegate(Unknown Source)
at $ConfigurableWebApplicationContext_38b45053c6a2.getBeanDefinitionCount(Unknown Source)
at org.apache.tapestry5.spring.SpringModule$1.initializeApplication(SpringModule.java:61)
at $ApplicationInitializer_38b45053c6be.initializeApplication(Unknown Source)
at org.apache.tapestry5.services.TapestryModule$40.initializeApplication(TapestryModule.java:2438)
at $ApplicationInitializer_38b45053c6be.initializeApplication(Unknown Source)
at $ApplicationInitializer_38b45053c6ba.initializeApplication(Unknown Source)
at org.apache.tapestry5.services.TapestryModule$ServletApplicationInitializerTerminator.initializeApplication(TapestryModule.java:279)
at $ServletApplicationInitializer_38b45053c69f.initializeApplication(Unknown Source)
at org.apache.tapestry5.TapestryFilter.init(TapestryFilter.java:116)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.mortbay.start.Main.invokeMain(Main.java:194)
at org.mortbay.start.Main.start(Main.java:534)
at org.mortbay.start.Main.start(Main.java:441)
at org.mortbay.start.Main.main(Main.java:119)
它seeems要與/WEB-INF/applicationContext.xml
有問題吧?讓我們來看看。
/WEB-INF/applicationContext.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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- Enable the Spring MVC stuff -->
<mvc:annotation-driven/>
<!-- Enable usage of @Autowired. -->
<context:annotation-config/>
<!-- Enable component scanning for defining beans with annotations. -->
<context:component-scan base-package="com.viktortech.automaton.model"/>
<!-- For translating native persistence exceptions to Spring's
DataAccessException hierarchy. -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.mortbay.naming.InitialContextFactory</prop>
<prop key="java.naming.provider.url">org.mortbay.naming</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>jdbc/appDB</value>
</property>
</bean>
<!-- ***********************************************************************
To avoid requesting unnecessary connections (not necessary for
MiniBank) with the Open Session in View filter, uncomment this and
change "sessionFactory" bean (bellow) to use "dataSourceProxy" instead
of "dataSource".
<bean id="dataSourceProxy" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy"
p:targetDataSource-ref="dataSource"/>
******************************************************************* -->
<!-- Hibernate Session Factory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
p:dataSource-ref="dataSource"
p:configLocation="classpath:/automaton-hibernate-config.xml"/>
<!-- Transaction manager for a single Hibernate SessionFactory. -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
<!-- Enable the configuration of transactional behavior based on
annotations. -->
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="manageService"
class="com.viktortech.automaton.model.manageservice.ManageServiceImpl"/>
<bean id="botService"
class="com.viktortech.automaton.model.botservice.BotServiceImpl"/>
<context:component-scan base-package="com.viktortech.automaton.rest" />
</beans>
那麼這是什麼JNDI JDBC/appDB,在那裏的定義以及如何?向右走,它在/WEB-INF/jetty-env.xml
文件
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="viktor" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/appDB</Arg>
<Arg>
<New class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<Set name="driverClassName">com.mysql.jdbc.Driver</Set>
<Set name="url">jdbc:mysql://workingDBserver/database</Set>
<Set name="username">******</Set>
<Set name="password">******</Set>
</New>
</Arg>
</New>
</Configure>
所以這是它。正如我所說的,它在localhost:8080上運行得非常流暢,但是當部署到遠程Jetty服務器(Same jetty版本)時,它會運行503,然後產生上述錯誤。
請問,你需要任何其他資源來解決這個問題。提前致謝。
創建「數據源」bean是一個問題。如果數據源bean創建成功,將創建「sessionFactory」bean。既然你說它給你503錯誤,可能是數據庫服務關閉/它無法訪問。您確定您的遠程服務器上的應用程序可以連接到數據庫嗎? – vinay 2014-09-25 18:13:21
100%確定,因爲數據庫服務器不在本地主機上。我敢肯定,它可以遠程訪問和所有這些東西(已經測試) – Trigork 2014-09-25 18:15:06
難道是jetty-env.xml中的數據源ID是'viktor'而不是'appDB'?它不應該改變任何東西的JNDI,但... – Trigork 2014-09-25 18:20:09