【问题标题】:Spring context is not loading after deploying on tomcat在 tomcat 上部署后未加载 Spring 上下文
【发布时间】:2015-12-24 19:11:02
【问题描述】:

我正在尝试在部署战争时加载 Spring 批处理作业上下文文件。

我已经添加了 contextConfigLocation 如下但没有工作。即使在 pom.xml 中添加了 spring-web 但是当我将我的 war 应用程序部署到 tomcat 时仍然没有初始化。请帮助我,因为我已经提到了大部分 SO 和春季论坛回答,我不想使用调度程序 servlet,因为这不是一个 Web 应用程序,因为它现在只是一个批处理作业,但将来它将是一个批处理作业 + Web 应用程序,那时我将有一个调度程序 servlet .请告诉我如何在服务器启动时加载弹簧。

存在完整代码的我的 git 存储库 https://github.com/sumateja/patternfinder https://github.com/sumateja/patternfinder.git

tomcat 日志

Dec 25, 2015 12:20:59 AM 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: C:\Program Files\Java\jdk1.7.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk1.7.0_45\bin;C:\Development\apache-maven-3.1.1\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\MySQL\MySQL Enterprise Backup 3.12\;C:\Program Files\Git\cmd;C:\Ruby21-x64\bin;C:\Users\Tejas\AppData\Local\Programs\Python\Python35-32\Scripts\;C:\Users\Tejas\AppData\Local\Programs\Python\Python35-32\;C:\Users\Tejas\AppData\Local\Programs\Python\Launcher\;C:\Users\Tejas\AppData\Roaming\npm;C:\Program Files\Git\bin;.
    Dec 25, 2015 12:20:59 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:patternfinder' did not find a matching property.
    Dec 25, 2015 12:20:59 AM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler ["http-bio-9090"]
    Dec 25, 2015 12:20:59 AM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler ["ajp-bio-9009"]
    Dec 25, 2015 12:20:59 AM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 548 ms
    Dec 25, 2015 12:20:59 AM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    Dec 25, 2015 12:20:59 AM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
    Dec 25, 2015 12:20:59 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["http-bio-9090"]
    Dec 25, 2015 12:20:59 AM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler ["ajp-bio-9009"]
    Dec 25, 2015 12:20:59 AM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 547 ms

web.xml

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:equity-eod-job.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

【问题讨论】:

    标签: spring spring-mvc tomcat


    【解决方案1】:

    我在我的机器上克隆了你的项目。我做了“mvn clean package”。当我准备将 war 文件从目标文件夹复制到 tomcat webapps 文件夹时,我注意到您将其打包为 jar 而不是 war。 :)

    改变你的 pom.xml,从 jar 到 war 的包装值:

        <modelVersion>4.0.0</modelVersion>
        <groupId>patternfinder</groupId>
        <artifactId>patternfinder</artifactId>
        <packaging>war</packaging>    <!-- This line from jar to war-->
        <version>1.0</version>
        <name>patternfinder</name>
    

    之后做:

    1. mvn 清洁包
    2. 将 target/patternfinder-1.0.war 复制到 tomcat webapp 文件夹中
    3. 启动tomcat

    现在您可以看到您的应用程序将开始加载。似乎有一个错误的文件路径,在日志中你可以发现 FileNotFoundException 发生。我希望你能解决这个问题。

    【讨论】:

    • 谢谢prem ...但是在我在eclipse中的代码中,我早先将它作为war包装保存,但它仍然无法正常工作。我正在使用全新安装,然后使用Add向tomcat添加war /删除选项。
    【解决方案2】:

    是的,终于解决了。似乎我的 web.xml 没有被拾取,因为 openshift 已将 web.xml 放在 webapps 文件夹中。因此在将 WEB-INF 文件夹复制到 WebContent 后删除了此文件夹。当我们将在 openshift 中创建的项目下载到我们的工作区时, web.xml 存在于 webapps 文件夹中。感谢 prem 的帮助。

    【讨论】:

      猜你喜欢
      • 2017-04-29
      • 2017-12-17
      • 2015-09-03
      • 2021-03-24
      • 2017-05-02
      • 1970-01-01
      • 2012-09-08
      • 2018-03-23
      • 2015-06-09
      相关资源
      最近更新 更多