2017-07-29 58 views
0

我有一個基於Spring MVC的服務器。當我使用mvn jetty: run命令運行此應用程序時,它運行正常。但是,當我使用mvn clean package命令運行並將我的.war發送到Jetty容器時,此應用程序被初始化兩次。Spring Java應用程序在Jetty上啓動兩次

我相信問題是在我的Jetty的配置,因爲在啓動時通過mvn jetty: run它正常運行。

這是我的pom.xml:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://maven.apache.org/POM/4.0.0" 
     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>...</groupId> 
    <artifactId>...</artifactId> 
    <version>...</version> 
    <packaging>war</packaging> 

    <properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <spring.version>4.2.1.RELEASE</spring.version> 
    <mail.version>1.5.4</mail.version> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 
    </properties> 

    <build> 

    <plugins> 
     <!-- WAR --> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-war-plugin</artifactId> 
     <version>2.6</version> 
     <configuration> 
      <failOnMissingWebXml>false</failOnMissingWebXml> 
     </configuration> 
     </plugin> 

     <!-- Compile --> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.1</version> 
     <configuration> 
      <source>${maven.compiler.source}</source> 
      <target>${maven.compiler.target}</target> 
      <encoding>UTF-8</encoding> 
     </configuration> 
     </plugin> 

     <!-- Properties --> 
     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>properties-maven-plugin</artifactId> 
     <version>1.0.0</version> 
     <executions> 
      <execution> 
      <phase>validate</phase> 
      <goals> 
       <goal>read-project-properties</goal> 
      </goals> 
      <configuration> 
       <files> 
       .. 
       </files> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 

     <!-- Flyway --> 
     <plugin> 
     <groupId>org.flywaydb</groupId> 
     <artifactId>flyway-maven-plugin</artifactId> 
     <version>3.2.1</version> 
     <executions> 
      <execution> 
      <id>flyway_medical_box_db</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>info</goal> 
       <goal>repair</goal> 
       <goal>migrate</goal> 
      </goals> 
      <configuration> 
       <baselineOnMigrate>true</baselineOnMigrate> 
       <driver>${jdbc.driver}</driver> 
       <url>${jdbc.url}</url> 
       <user>${jdbc.username}</user> 
       <password>${jdbc.password}</password> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 

     <!-- Jetty 
     <plugin> 
     <groupId>org.eclipse.jetty</groupId> 
     <artifactId>jetty-maven-plugin</artifactId> 
     <version>9.2.12.v20150709</version> 
     <configuration> 
      <systemProperties> 
      <systemProperty> 
       <name>org.eclipse.jetty.util.log.Log</name> 
       <value>org.eclipse.jetty.util.log.Slf4jLog</value> 
      </systemProperty> 
      <systemProperty> 
       <name>logback.configurationFile</name> 
       <value>${project.basedir}/src/main/resources/logback.xml</value> 
      </systemProperty> 
      </systemProperties> 
     </configuration> 
     </plugin>--> 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-install-plugin</artifactId> 
     <version>2.5.2</version> 
     <executions> 
      <execution> 
      <id>pagseguro</id> 
      <phase>validate</phase> 
      <goals> 
       <goal>install-file</goal> 
      </goals> 
      <configuration> 
       <groupId>br.com.uol.pagseguro</groupId> 
       <artifactId>pagseguro</artifactId> 
       <version>2.5.2</version> 
       <packaging>jar</packaging> 
       <file>${project.basedir}/src/main/resources/vendor/pagseguro/pagseguro-api-2.5.2.jar</file> 
      </configuration> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

    <dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context-support</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
     <exclusions> 
     <exclusion> 
      <groupId>commons-logging</groupId> 
      <artifactId>commons-logging</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-orm</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.websocket</groupId> 
     <artifactId>javax.websocket-api</artifactId> 
     <version>1.1</version> 
    </dependency> 

    <dependency> 
     <groupId>com.squareup.okhttp3</groupId> 
     <artifactId>okhttp</artifactId> 
     <version>3.2.0</version> 
    </dependency> 

    <!-- Security --> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <version>4.0.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>4.0.2.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.security.oauth</groupId> 
     <artifactId>spring-security-oauth2</artifactId> 
     <version>2.0.7.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hashids</groupId> 
     <artifactId>hashids</artifactId> 
     <version>1.0.1</version> 
    </dependency> 

    <!-- Jackson --> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 
     <version>2.6.4</version> 
    </dependency> 

    <dependency> 
     <groupId>com.fasterxml.jackson.dataformat</groupId> 
     <artifactId>jackson-dataformat-xml</artifactId> 
     <version>2.6.4</version> 
    </dependency> 

    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
     <version>20151123</version> 
    </dependency> 

    <!-- Apache Commons Lang --> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
     <version>3.4</version> 
    </dependency> 

    <dependency> 
     <groupId>com.github.slugify</groupId> 
     <artifactId>slugify</artifactId> 
     <version>2.1.3</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
     <version>1.9.2</version> 
    </dependency> 

    <!-- Mime Type --> 
    <dependency> 
     <groupId>org.apache.tika</groupId> 
     <artifactId>tika-core</artifactId> 
     <version>1.11</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-codec</groupId> 
     <artifactId>commons-codec</artifactId> 
     <version>1.10</version> 
    </dependency> 

    <!-- File Upload --> 
    <dependency> 
     <groupId>commons-fileupload</groupId> 
     <artifactId>commons-fileupload</artifactId> 
     <version>1.3.1</version> 
    </dependency> 

    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
     <version>2.4</version> 
    </dependency> 

    <!-- Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>5.0.2.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-ehcache</artifactId> 
     <version>5.0.2.Final</version> 
     <exclusions> 
     <exclusion> 
      <groupId>net.sf.ehcache</groupId> 
      <artifactId>ehcache</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>net.sf.ehcache</groupId> 
     <artifactId>ehcache-core</artifactId> 
     <version>2.6.11</version> 
     <exclusions> 
     <exclusion> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>5.2.1.Final</version> 
    </dependency> 

    <dependency> 
     <groupId>com.fasterxml.jackson.datatype</groupId> 
     <artifactId>jackson-datatype-hibernate5</artifactId> 
     <version>2.6.4</version> 
    </dependency> 

    <!-- Connection Pool --> 
    <dependency> 
     <groupId>com.zaxxer</groupId> 
     <artifactId>HikariCP</artifactId> 
     <version>2.4.3</version> 
    </dependency> 

    <!-- Repository --> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-jpa</artifactId> 
     <version>1.9.1.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>4.0.5.RELEASE</version> 
    </dependency> 

    <dependency> 
     <groupId>org.postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.4-1201-jdbc41</version> 
    </dependency> 

    <!-- Mail --> 
    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>javax.mail-api</artifactId> 
     <version>${mail.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>com.sun.mail</groupId> 
     <artifactId>javax.mail</artifactId> 
     <version>${mail.version}</version> 
    </dependency> 

    <!-- Log --> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>jcl-over-slf4j</artifactId> 
     <version>1.7.13</version> 
    </dependency> 

    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
     <version>1.1.3</version> 
    </dependency> 

    <!-- Test --> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.12</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-core</artifactId> 
     <version>1.10.19</version> 
     <scope>test</scope> 
     <exclusions> 
     <exclusion> 
      <groupId>org.hamcrest</groupId> 
      <artifactId>hamcrest-core</artifactId> 
     </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>commons-httpclient</groupId> 
     <artifactId>commons-httpclient</artifactId> 
     <version>3.1</version> 
    </dependency> 

    <dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time</artifactId> 
     <version>2.9.9</version> 
    </dependency> 
    </dependencies> 
</project> 

這是我的jetty.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> 

<Configure class="org.eclipse.jetty.webapp.WebAppContext"> 
    <Set name="contextPath">/</Set> 
    <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/myapp.war</Set> 
    <Set name="extractWAR">true</Set> 
</Configure> 

這是我start.ini:

#=========================================================== 
# Jetty Startup 
# 
# Starting Jetty from this {jetty.home} is not recommended. 
# 
# A proper {jetty.base} directory should be configured, instead 
# of making changes to this {jetty.home} directory. 
# 
# See documentation about {jetty.base} at 
# http://www.eclipse.org/jetty/documentation/current/startup.html 
# 
# A demo-base directory has been provided as an example of 
# this sort of setup. 
# 
# $ cd demo-base 
# $ java -jar ../start.jar 
# 
#=========================================================== 

# To disable the warning message, comment the following line 
--module=home-base-warning 

# --------------------------------------- 
# Module: ext 
--module=ext 


# --------------------------------------- 
# Module: resources 
--module=resources 


# --------------------------------------- 
# Module: server 
--module=server 

### ThreadPool configuration 
## Minimum number of threads 
# jetty.threadPool.minThreads=10 

## Maximum number of threads 
# jetty.threadPool.maxThreads=200 

## Thread idle timeout (in milliseconds) 
# jetty.threadPool.idleTimeout=60000 

### Common HTTP configuration 
## Scheme to use to build URIs for secure redirects 
# jetty.httpConfig.secureScheme=https 

## Port to use to build URIs for secure redirects 
# jetty.httpConfig.securePort=8443 

## Response content buffer size (in bytes) 
# jetty.httpConfig.outputBufferSize=32768 

## Max response content write length that is buffered (in bytes) 
# jetty.httpConfig.outputAggregationSize=8192 

## Max request headers size (in bytes) 
# jetty.httpConfig.requestHeaderSize=8192 

## Max response headers size (in bytes) 
# jetty.httpConfig.responseHeaderSize=8192 

## Whether to send the Server: header 
# jetty.httpConfig.sendServerVersion=true 

## Whether to send the Date: header 
# jetty.httpConfig.sendDateHeader=false 

## Max per-connection header cache size (in nodes) 
# jetty.httpConfig.headerCacheSize=512 

## Whether, for requests with content, delay dispatch until some content has arrived 
# jetty.httpConfig.delayDispatchUntilContent=true 

## Maximum number of error dispatches to prevent looping 
# jetty.httpConfig.maxErrorDispatches=10 

### Server configuration 
## Whether ctrl+c on the console gracefully stops the Jetty server 
# jetty.server.stopAtShutdown=true 

## Dump the state of the Jetty server, components, and webapps after startup 
# jetty.server.dumpAfterStart=false 

## Dump the state of the Jetty server, components, and webapps before shutdown 
# jetty.server.dumpBeforeStop=false 

# --------------------------------------- 
# Module: http 
--module=http 

### HTTP Connector Configuration 

## Connector host/address to bind to 
# jetty.http.host=0.0.0.0 

## Connector port to listen on 
# jetty.http.port=8080 

## Connector idle timeout in milliseconds 
# jetty.http.idleTimeout=30000 

## Connector socket linger time in seconds (-1 to disable) 
# jetty.http.soLingerTime=-1 

## Number of acceptors (-1 picks default based on number of cores) 
# jetty.http.acceptors=-1 

## Number of selectors (-1 picks default based on number of cores) 
# jetty.http.selectors=-1 

## ServerSocketChannel backlog (0 picks platform default) 
# jetty.http.acceptorQueueSize=0 

## Thread priority delta to give to acceptor threads 
# jetty.http.acceptorPriorityDelta=0 

# --------------------------------------- 
# Module: deploy 
--module=deploy 

# Monitored directory name (relative to $jetty.base) 
# jetty.deploy.monitoredDir=webapps 

# Monitored directory scan period (seconds) 
# jetty.deploy.scanInterval=1 

# Whether to extract *.war files 
# jetty.deploy.extractWars=true 

# --------------------------------------- 
# Module: jsp 
--module=jsp 


# --------------------------------------- 
# Module: websocket 
--module=websocket 


# --------------------------------------- 
# Module: jstl 
--module=jstl 


--module=ssl 
--module=https 
+2

歡迎來到Stackoverflow。 「把我的戰爭發送到碼頭集裝箱」意味着什麼?你好嗎?你如何啓動碼頭集裝箱?你的'$ {jetty.base}'目錄是什麼樣的?你粘貼了'$ {jetty.home}/start.ini',但這不應該被使用(甚至在那個文件頭中這麼說)! –

+0

你如何「發送我的.war到Jetty容器」 - UPS或聯邦快遞? :) –

回答

0

我發現了什麼我錯誤是。

在我的webapps文件夾中,我的.xml與我的啓動配置和我的.war。我只是更改.war文件的文件夾,我將.xml保存在webapps文件夾中,並且應用程序不會啓動兩次。

相關問題