2016-03-01 130 views
0

我想將我的Spring啓動應用程序(.war)部署到外部Tomcat服務器。我的應用程序在Eclipse中使用我的本地Tomcat 8和jdk 8正常工作。此外,我們正在使用maven和部署春季啓動戰爭給Tomcat 8

現在,我們必須從頭開始設置整個服務器,並盡力做到最好,但應用程序不會找到任何服務。我們可以調用靜態html,css和js文件。就我們想要調用服務而言,我們得到了404錯誤。

任何人都可以告訴我一步一步設置tomcat部署戰爭?

這裏是我的startclass:

@PropertySources({ 
     @PropertySource("classpath:/application.properties"), 
     @PropertySource("classpath:/messages_de.properties") 
}) 
@SpringBootApplication 
public class Application { 
    public static void main(String[] args) throws Exception { 
     SpringApplication springApplication = new SpringApplication(Application.class); 
     springApplication.run(args); 
    } 
} 

下面是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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>de.quanto</groupId> 
    <artifactId>QuantoSpringMVC</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>QuantoSpringMVC Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.3.2.RELEASE</version> 
    </parent> 
    <dependencies> 
     <dependency> 
      <groupId>javax</groupId> 
      <artifactId>javaee-web-api</artifactId> 
      <version>7.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <!-- for JPA, use hibernate-entitymanager instead of hibernate-core --> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.36</version> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.persistence</groupId> 
      <artifactId>org.eclipse.persistence.jpa</artifactId> 
      <version>2.6.1-RC1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.persistence</groupId> 
      <artifactId>persistence-api</artifactId> 
      <version>1.0.2</version> 
     </dependency> 
     <!-- Used for generating hibernate-model classes >>> --> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-tools</artifactId> 
      <version>4.3.2.Final</version> 
      <scope>compile</scope> 
      <exclusions> 
       <exclusion> 
        <artifactId>log4j</artifactId> 
        <groupId>log4j</groupId> 
       </exclusion> 
       <exclusion> 
        <artifactId>slf4j-api</artifactId> 
        <groupId>org.slf4j</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.eclipse.equinox</groupId> 
      <artifactId>app</artifactId> 
      <version>1.3.200-v20130910-1609</version> 
     </dependency> 
     <!-- <<< --> 
     <!-- SPRING DEPENDENCIES/REPO/PLUGINS STARTS HERE --> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
      <exclusions> 
       <exclusion> 
        <artifactId>jcl-over-slf4j</artifactId> 
        <groupId>org.slf4j</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
      <exclusions> 
       <exclusion> 
        <artifactId>slf4j-api</artifactId> 
        <groupId>org.slf4j</groupId> 
       </exclusion> 
       <exclusion> 
        <artifactId>jcl-over-slf4j</artifactId> 
        <groupId>org.slf4j</groupId> 
       </exclusion> 
      </exclusions> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-tomcat</artifactId> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <version>1.3.2.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>${springframework.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>${springframework.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-webmvc</artifactId> 
      <version>${springframework.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-orm</artifactId> 
      <version>${springframework.version}</version> 
     </dependency> 
     <!-- SECURITY START --> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-core</artifactId> 
      <version>4.0.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-web</artifactId> 
      <version>4.0.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.security</groupId> 
      <artifactId>spring-security-config</artifactId> 
      <version>4.0.3.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>commons-dbcp</groupId> 
      <artifactId>commons-dbcp</artifactId> 
      <version>1.4</version> 
     </dependency> 
     <!-- SECURITY ENDS --> 
     <!-- Authentification (Access Directory...) --> 
     <dependency> 
      <groupId>org.springframework.security.oauth</groupId> 
      <artifactId>spring-security-oauth2</artifactId> 
      <version>2.0.8.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.modelmapper</groupId> 
      <artifactId>modelmapper</artifactId> 
      <version>0.7.5</version> 
     </dependency> 
     <dependency> 
      <groupId>org.modelmapper.extensions</groupId> 
      <artifactId>modelmapper-spring</artifactId> 
      <version>0.7.5</version> 
     </dependency> 
    </dependencies> 
    <properties> 
     <springframework.version>4.2.4.RELEASE</springframework.version> 
     <java.version>1.7</java.version> 
     <tomcat.version>8.0.32</tomcat.version> 
    </properties> 
    <repositories> 
     <repository> 
      <id>spring-releases</id> 
      <url>https://repo.spring.io/libs-release</url> 
     </repository> 
    </repositories> 
    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-releases</id> 
      <url>https://repo.spring.io/libs-release</url> 
     </pluginRepository> 
    </pluginRepositories> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
     <finalName>QuantoSpringMVC</finalName> 
    </build> 
</project> 

回答

1

您需要使用文本其新的變化來更新你的經理網址

<plugin> 
       <groupId>org.apache.tomcat.maven</groupId> 
       <artifactId>tomcat8-maven-plugin</artifactId> 
       <version>{version}</version> 
       <configuration> 
        <url>http://yourRemoteServer:8888/manager/text</url> 
        <server>TomcatServer</server> 
        <path>/{project.artifactId}</path> 
       </configuration> 
      </plugin> 

現在您可以運行mvn tomcat7:部署(或重新部署)

PS:我知道命令tomcat7:deploy(redeploy)存在,但我不確定tomcat8:部署!

+0

難道是我的網址在** manager/html **上結束? 我還需要在這個插件中自定義什麼? 我使用eclipse中的「maven install」,然後在tomcat管理器gui的幫助下部署.war。這可以工作嗎? – Andy

+0

這種方法被認爲是使用插件tomcat。對於這個插件,'\ text'擴展名是關於使用tomcat 6和tomcat 7進行部署的更新。不幸的是,我知道這個解決方案,但如果你嘗試直接與你的經理部署貴我不知道這將工作。 – Hohenheim

+0

現在正在工作。我們安裝了正確的java 8版本。然後在pom.xml中設置上面的代碼,使用「maven install」並通過gui進行上傳。 – Andy