![](/img/trans.png)
[英]Directory configuration while deploying java standalone program to Tomcat server
[英]Deploying a Java Spring, REST and Angular JS app on a standalone Tomcat Server
我使用Intellij IDE创建了Java Spring和AngularJS应用程序。 我在intellij中创建了一个war(Web Application:Exploded)文件。 我将这个war文件放在Tomcat webapps目录中,并很好地部署了AngularJS代码,可以在浏览器中打开它。 当我尝试使用REST调用来调用服务器代码时,出现404 not found错误,并且可以看到tomcat目录中没有Java文件。 我复制了Java文件,但仍然不高兴。 我是部署Web应用程序的新手。
如果有人可以帮助我如何使angularJS文件正确调用我的Java ,将不胜感激。
谢谢。
Spring-Module.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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="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">
<context:component-scan base-package="com.services.impl"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Creating TransactionManager Bean, since JDBC we are creating of type
DataSourceTransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="getUserRepo" class="com.Repo.impl.UserRepoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataManipulationRepo" class="com.Repo.impl.DataManipulationRepoImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://127.0.0.1/xx"/>
<property name="username" value="root"/>
<property name="password" value="xx"/>
</bean>
</beans>
mvc-dispatcher-servlet:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.controller"/>
<mvc:resources mapping="/app/**" location="/app/build/"/>
<mvc:annotation-driven/>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
项目结构
WEB-INF
|_ jsp folder
|_ lib folder
|_ web.xml
|_ mvc-dispatcher-servlet.xml
|_ classes folder
|_ com folder (controller, model, services, resources, Repo folders with .class files within each)
|_ Spring-Module.xml
app
|_ html files
解
我知道了!! 我的REST通话是大写字母。 我在调用中使用大写字母表示项目名称,然后在引起问题的浏览器URL中使用小写字母。 使用chrome Postman应用程序也确实很有帮助。
根据您的答案,您已经使用IntelliJ创建了项目的.war文件。 基于此,请按照以下步骤操作,以便在tomcat中正确部署您的应用程序。 以下说明基于linux或mac系统。
<tomcat-home>
。 例如/var/local/apache-tomcat-8/
<tomcat-home>
内部,您会找到一些文件夹,例如webapps
, log
和bin
。 webapps
文件夹,然后在其中放置.war文件。 默认情况下,tomcat仅在运行.war文件时才尝试部署它。 如果tomcat没有运行,请转到bin
文件夹并找到一个名为startup.sh
文件,然后执行该文件(仅适用于Linux系统),例如<tomcat-home>/bin/startup.sh
。 执行startup.sh时,您将看到为tomcat设置的环境变量,例如CATALINA_HOME,JRE_HOME和其他,如果tomcat无法启动,则会显示错误消息。 webapp
文件夹,看是否有新文件夹,例如,如果我有myapp.war
则tomcat应该创建一个名为myapp
的文件夹,并且该文件夹中应该存在WEB-INF
或META-INF
文件夹,这是Java Web应用程序的标准。 WEB-INF
文件夹,因为它里面应该是一个classes
和lib
文件夹,在classes
文件夹中仅存在.class文件,这些文件组织在文件夹中,具体取决于软件包的组织。 在lib
文件夹中应该存在与您的项目相关的所有.jar文件夹,例如spring,hibernate和许多其他文件夹。 log
文件夹中查找并在其中找到一个catalina.out
文件,然后阅读该文件以查看任何错误消息。 ps -ef | grep java
ps -ef | grep java
stop
tomcat,请转到bin
文件夹并执行shutdown.sh.
为了查看如何正确生成.war文件,您可以转到此文章IntelliJ社区找不到Web应用程序工件来生成WAR
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.