2017-08-19 33 views
1

我使用Intellij IDE创建了Java Spring和AngularJS应用程序。我在intellij中创建了一个war(Web应用程序:分解)文件。我把这个war文件放在Tomcat的webapps目录中,并且AngularJS代码部署的很好,我可以在浏览器中打开它。当我尝试使用REST调用调用我的服务器代码时,我得到404未找到错误,我可以看到tomcat目录中没有Java文件。我复制了java文件,但仍然没有喜悦。 我是部署Web应用程序的新手。在独立的Tomcat服务器上部署Java Spring,REST和Angular JS应用程序

如果有人可以请帮我我怎么能得到angularJS文件调用我的java正确,将不胜感激。

谢谢。

弹簧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-调度员的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邮递员应用程序也很有帮助。

+0

只有一个观察,.java文件是用java语言编写的人类可读代码,它不能被JVM直接执行,为了让tomcat执行你的java应用程序,请确保.class文件存在(.class文件是th e编译的java文件)。在tomcat标准部署中,总是有一个WEB-INF文件夹试图验证.class或.jar文件是否存在于该文件夹中。同时验证tomcat的日志文件夹,以便查看部署过程中真正发生的情况。 –

+0

你开始了你的tomcat吗? – akuma8

+0

@DanielC。谢谢您的回复。我从我的intellij项目复制了.class文件,并将它们粘贴到WEB-INF/classes目录中。这是做到这一点的正确方法吗?这是我拥有的目录结构。 \ tomcat \ webapps \ LAS \\ build \ WEB-INF \ classes \ com \ controller - 在控制器文件夹内我复制了.Java和.class文件。但是,当我进行REST调用时,部署日志没有错误我收到404错误。我的java类有一个包:com.controller。任何帮助是极大的赞赏。谢谢。 – drea

回答

0

根据您的回答,您已经使用IntelliJ创建了项目的.war文件。基于此步骤,以便在tomcat中正确部署您的应用程序。以下说明基于Linux或Mac系统。

  1. 转到您的Apache Tomcat的家,我们将这个目录叫为<tomcat-home>。例如/var/local/apache-tomcat-8/
  2. Inside <tomcat-home>您会发现一些文件夹,如webapps,log,bin
  3. 转到webapps文件夹并在其上放置.war文件。默认情况下,只有在运行时,tomcat才会尝试部署.war文件。如果tomcat没有运行,那么去bin文件夹,找到一个名为startup.sh的文件,并执行它(仅适用于linux系统),像这样<tomcat-home>/bin/startup.sh。执行startup.sh时,您将看到为tomcat设置的环境变量,如CATALINA_HOME,JRE_HOME和其他,如果tomcat无法启动,则会显示错误消息。
  4. 第一次评估做的是检讨webapp文件夹,看看是否有上有一个新的文件夹,例如,如果我有myapp.war则在Tomcat应该创建一个名为myapp文件夹,该文件夹内应该存在一个WEB-INFMETA-INF文件夹,这是java web应用程序的标准。
  5. 查看WEB-INF文件夹,因为它里面应该是一个classeslib文件夹,在文件夹classes只存在于这取决于包文件夹组织举办的.class文件。在lib文件夹中应该存在与您的项目相关的所有.jar文件夹,如spring,hibernate和其他许多文件夹。
  6. 最后看log文件夹里面有一个catalina.out文件,并阅读它看到任何错误消息。
  7. 在linux看看Tomcat的运行,你可以通过这个突击队ps -ef | grep java
  8. 检查为了stop tomcat的去bin文件夹,并执行shutdown.sh.

为了看如何生成.war文件正确的你可以去这篇文章IntelliJ community can't find Web Application Artifact to generate WAR

+0

这是非常好的。非常感谢你。我遵循了这些步骤,创造了这场战争,并且完全部署了它。然而,我仍然得到一个404没有在我的服务器休息电话找到。我不知道还有什么可能导致这个问题?我正在使用spring-mvc-dispatcher文件来配置 – drea

+0

,任何帮助都很棒。感谢您的所有帮助。 – drea

+0

你能否提供弹簧配置?也是你项目的文件夹结构。 –

相关问题