簡體   English   中英

在獨立的Tomcat服務器上部署Java Spring,REST和Angular JS應用

[英]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系統。

  1. 轉到您的Apache tomcat主頁,我們將此目錄稱為<tomcat-home> 例如/var/local/apache-tomcat-8/
  2. <tomcat-home>內部,您會找到一些文件夾,例如webappslogbin
  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 ps -ef | grep java
  8. 為了stop tomcat,請轉到bin文件夾並執行shutdown.sh.

為了查看如何正確生成.war文件,您可以轉到此文章IntelliJ社區找不到Web應用程序工件來生成WAR

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM