2015-03-31 132 views
0

我目前面臨的問題是,我的api打包成WAR(使用eclipse + maven)之後,我的api將無法在我的Jetty上啓動。從Eclipse啓動時可以正常工作。NoInitialContextException與Jetty,Jersey&Spring

我從我的碼頭一看日誌,發現:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxDS' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512) 

有了根本原因:

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) 
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) 
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) 
at javax.naming.InitialContext.lookup(InitialContext.java:411) 
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) 
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) 
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) 

我是新來春+碼頭。我在這裏查看了一下stackoverflow,並發現了入口類或類似配置缺失的東西,但到現在爲止沒有任何工作。我使用

我是什麼:

  • 碼頭9
  • 的Apache 2
  • 的Java 7
  • 澤西2
  • Debian的喘息
  • 的MySQL 5.5

而且剪斷從我的ap plication-context.xml:

<bean id="xxDS" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton"> 
    <property name="jndiName" value="java:comp/env/jdbc/xxDB" /> 
    <property name="resourceRef" value="true" /> 
</bean> 

任何幫助表示讚賞。

更新 - 完整的日誌:

.20:46:20.338 [main] ERROR o.s.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/applicationContext.xml]: Cannot resolve reference to bean 'xxDS' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxDS' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:326) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at 
    ... 
    org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:455) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235) [jetty-deploy-9.2.10.v20150310.jar:9.2.10.v20150310] 
    at 
    ... 
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_75] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_75] 
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_75] 
    at org.eclipse.jetty.start.Main.invokeMain(Main.java:321) [start.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.start.Main.start(Main.java:817) [start.jar:9.2.10.v20150310] 
    at org.eclipse.jetty.start.Main.main(Main.java:112) [start.jar:9.2.10.v20150310] 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxDS' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    ... 57 common frames omitted 
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) ~[na:1.7.0_75] 
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) ~[na:1.7.0_75] 
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) ~[na:1.7.0_75] 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_75] 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) ~[spring-context-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE] 
    ... 64 common frames omitted 
2015-04-01 20:46:20.339:WARN:oejw.WebAppContext:main: Failed startup of context [email protected]{/api,file:/opt/jetty/temp/jetty-0.0.0.0-8080-api.war-_api-any-11240862.dir/webapp/,STARTING}{/api.war} 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/applicationContext.xml]: Cannot resolve reference to bean 'xxDS' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxDS' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:326) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at 
    ... 
    org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) 
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186) 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498) 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:455) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609) 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528) 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391) 
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560) 
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235) 
    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:387) 
    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.Server.doStart(Server.java:354) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174) 
    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.eclipse.jetty.start.Main.invokeMain(Main.java:321) 
    at org.eclipse.jetty.start.Main.start(Main.java:817) 
    at org.eclipse.jetty.start.Main.main(Main.java:112) 
Caused by: 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxDS' defined in class path resource [spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) 
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444) 
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294) 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) 
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186) 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498) 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:455) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609) 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528) 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391) 
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560) 
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235) 
    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:387) 
    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.Server.doStart(Server.java:354) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174) 
    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.eclipse.jetty.start.Main.invokeMain(Main.java:321) 
    at org.eclipse.jetty.start.Main.start(Main.java:817) 
    at org.eclipse.jetty.start.Main.main(Main.java:112) 
Caused by: 
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial 
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) 
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) 
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) 
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) 
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) 
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) 
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) 
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231) 
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) 
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1417) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1158) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) 
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800) 
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444) 
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791) 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294) 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1349) 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1342) 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:505) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) 
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186) 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:498) 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:146) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:455) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:609) 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:528) 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:391) 
    at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:560) 
    at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:235) 
    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:387) 
    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.Server.doStart(Server.java:354) 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174) 
    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.eclipse.jetty.start.Main.invokeMain(Main.java:321) 
    at org.eclipse.jetty.start.Main.start(Main.java:817) 
    at org.eclipse.jetty.start.Main.main(Main.java:112) 
+0

你在哪裏定義的Java':comp/env的/ JDBC/xxDB'? – jny 2015-03-31 16:18:12

+0

我在persistence-xx.xml中定義了/ jdbc/xxDB。跟隨thix示例:http://www.codingpedia.org/ama/java-persistence-example-with-spring-jpa2-and-hibernate/ – DominikAngerer 2015-04-01 07:04:56

回答

1

我刪除一個線從我的pom.xml,它告訴碼頭說,那些沒有提供相關性。之後,它運行在我的示例tomcat,所以我現在住在一個tomcat。

編輯:

更改:

<!-- tomcat jdbc --> 
    <dependency> 
     <groupId>org.apache.tomcat</groupId> 
     <artifactId>tomcat-jdbc</artifactId> 
     <version>7.0.35</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.27</version> 
     <scope>provided</scope> 
    </dependency> 

到:

<!-- tomcat jdbc --> 
    <dependency> 
     <groupId>org.apache.tomcat</groupId> 
     <artifactId>tomcat-jdbc</artifactId> 
     <version>7.0.35</version> 
    </dependency> 

    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.27</version> 
    </dependency> 

此外,我還無法得到它與碼頭工作 - 所以我還是去tomcat

使用這個例子/引導應用:https://github.com/amacoder/demo-restWS-spring-jersey-jpa2-hibernate

+0

您刪除了哪些行? – gstackoverflow 2015-04-29 10:39:48

+0

我會盡快編輯這個答案,以便您可以在pom.xml上找到更詳細的解決方案 - 對不起。 – DominikAngerer 2015-04-29 10:47:38

+0

@gstackoverflow添加了我的刪除行。 – DominikAngerer 2015-05-01 15:03:54