【问题标题】:How do I configure this Spring project correctly?如何正确配置此 Spring 项目?
【发布时间】:2012-01-23 18:17:07
【问题描述】:

我和我的团队正在尝试设置一个 Spring 项目,并希望实现 REST 服务。但是当我尝试将它部署到 tomcat 7 时,我得到一个错误。这是输出:

Jan 22, 2012 9:39:34 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Jan 22, 2012 9:39:34 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:niths' did not find a matching property.
Jan 22, 2012 9:39:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 22, 2012 9:39:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 22, 2012 9:39:34 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 497 ms
Jan 22, 2012 9:39:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 22, 2012 9:39:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.25
Jan 22, 2012 9:39:34 PM org.apache.catalina.startup.ContextConfig webConfig
SEVERE: Unable to determine URL for WEB-INF/classes
javax.naming.NameNotFoundException: Resource /WEB-INF/classes not found
    at org.apache.naming.resources.BaseDirContext.listBindings(BaseDirContext.java:733)
    at org.apache.naming.resources.ProxyDirContext.listBindings(ProxyDirContext.java:546)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1197)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:825)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:300)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5161)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1568)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1558)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

Jan 22, 2012 9:39:37 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Jan 22, 2012 9:39:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jan 22, 2012 9:39:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jan 22, 2012 9:39:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3208 ms

我试过谷歌搜索javax.naming.NameNotFoundException: Resource /WEB-INF/classes not found,但没有运气。我猜这个项目根本没有部署。

项目托管在this GitHub repo

我添加了一个非常简单的方法来测试我的应用程序:getBaz(),我猜它会在localhost:8080/niths/rest/baz 调用。

我很难弄清楚缺少什么,因为这是我的第一个 Spring 项目,因此如果精通 Spring 艺术的人能指出问题所在,我将不胜感激!

【问题讨论】:

  • 你是怎么把它部署到Tomcat的,把.war文件放进去?我使用了 maven jetty 插件来运行它—— org.mortbay.jettyjetty-maven-plugin 在 pom.xml 和 mvn jetty 中:运行——它似乎加载正常。
  • 谢谢!这部署了应用程序,您是否有机会让所谓的 REST 服务工作?

标签: spring jakarta-ee tomcat


【解决方案1】:

从您的 pom.xml 文件中,您似乎从生成的战争中排除了您的类和库:

<warSourceExcludes>WEB-INF/classes/**,WEB-INF/lib/**</warSourceExcludes>

删除此行再试一次。

【讨论】:

  • 它仍然显示javax.naming.NameNotFoundException: Resource /WEB-INF/classes not found,即使我完全删除了项目,重新下载并再次尝试。
  • 您观察到的错误似乎是 Tomcat 7.0.25 issue 52511 中的一个问题。通过this answer找到。
猜你喜欢
  • 2018-02-17
  • 2016-06-21
  • 2017-12-26
  • 1970-01-01
  • 2020-11-01
  • 2017-03-08
  • 2019-09-10
  • 2016-05-22
  • 1970-01-01
相关资源
最近更新 更多