【发布时间】:2018-03-28 06:19:13
【问题描述】:
我想将基于 Spring MVC 的 maven 项目部署到 Tomcat 服务器中。 我一直在本地模式下使用 eclipse + tomcat 7,并且该项目可以正常工作,但是现在,我购买了带有 PLESK 的主机,并且该应用程序无法正常工作。
我使用 maven 插件方法(目标全新安装,adn JDK 1.8 编译器)构建了一个 .WAR:
我使用普通的 wep 应用程序 .war 文件进行测试,并且主机正常工作,因此我认为问题是在构建 .war 文件之前我的项目的结构......但我不知道。
Sample.war 结构:
我目前的结构是这样的(使用 Spring MVC 的 Maven 项目):
我的 pom.xml 中的一行
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TreeBuk</groupId>
<artifactId>TreeBuk</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
我的 index.jsp 和我所有的其他视图都在 WebContent/WEB-INF/views 中。我看到了一些例子,其中 index.jsp 在 WebContent/WEB-INF/... 但我不知道为什么...另一方面,我也在本地服务器 tomcat 中测试它(在 eclipse 中没有实例)但不进行部署...我不明白为什么在 tomcat 实例上工作到 eclipse 中,但在本地 tomcat 服务器中不起作用。
谁能帮我在服务器上部署我的 wepApp?问题出在哪里?
PD:我使用 Apache Tiles 3.0,将一些 .xml 配置文件(security-context.xml、persistence-context.xml、service-context 等)放入 src/com.treebuk/config 以及 WebContent/WEB- INF/dispatcher-servlet.xml 文件)
编辑 1: 当启动执行 apache-tomcat-7.0.67\bin\startip.bat 的本地 tomcat 服务器时,我可以在控制台中看到:
如果我转到 url http://localhost:8080/TreeBuk/
编辑 2 在我的 web.xml 文件中,我配置了多上下文文件 xml。 (提醒该应用程序适用于 Eclipse 的 tomcat 服务器实例)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:com/treebuk/config/persistence-context.xml
classpath:com/treebuk/config/service-context.xml
classpath:com/treebuk/config/security-context.xml
classpath:com/treebuk/config/application-context.xml
</param-value>
</context-param>
【问题讨论】:
-
一个小建议,在java项目中使用intellij idea。你会惊讶于在 intellij 中的轻松做事。
-
您的异常表明,您构建的应用程序正在搜索名为
persistence-context.xml的文件,但它在您的类路径中不存在。你把这个文件放在那个路径上了吗? -
@AtaurRahmanMunna 当然,我将用于测试的配置 .xml 文件从 src/com/treebuk/config 更改为 WEB-INF,并将类路径值更改为 WEB-INF/persistence-context.xml。 . 并且信息消息更改为指示资源未找到....我也在尝试解决这个问题...但我不明白为什么在 eclipse 的 Tomcat 服务器实例和其他服务器中工作不...
-
让我们将
persistence-context.xml文件放入src/com/treebuk/config并对其进行测试。如果在生产模式下没问题,那么尝试逐步更改。
标签: java maven spring-mvc tomcat deployment