2016-12-28 69 views
2

@Outowired在將我的spring引導應用程序打包爲tomcat的war時部署爲null,但使用spring引導的嵌入式tomcat時可以正常工作。 請幫忙嗎?在Tomcat上部署時,Spring引導@Autowired Annotation不起作用

<?xml version="1.0" encoding="UTF-8"?> 

http://maven.apache.org/xsd/maven-4.0.0.xsd「> 4.0.0 flexedge-CSS 戰爭 flexedge-CSS 領事服務調度 融爲一體。 flexedge.css flexedge-CSS-BOM 0.2.0 UTF-8 UTF-8 1.8 vaadin-插件 http://maven.vaadin.com/vaadin-addons 真正

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-tomcat</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.vaadin.tapio</groupId> 
     <artifactId>googlemaps</artifactId> 
     <version>1.3.4</version> 
    </dependency> 
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.flexedge.css</groupId> 
     <artifactId>flexedge-css-ejb</artifactId> 
     <version>0.2.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.freemarker</groupId> 
     <artifactId>freemarker</artifactId> 
    </dependency> 
</dependencies> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>com.vaadin</groupId> 
      <artifactId>vaadin-bom</artifactId> 
      <version>7.7.3</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

+0

您是否遵循官方文檔中描述的所有步驟? http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file – Tome

回答

0

在我的應用程序下面的pom.xml文件做工精細,並在展開時單機的Tomcat also.Do檢查,如果你已經取得範圍,因爲提供的嵌入式服務器在你的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/xsd/maven-4.0.0.xsd"> 
      <modelVersion>4.0.0</modelVersion> 
      <groupId>com.springboot</groupId> 
      <artifactId>SpringBootExamples</artifactId> 
      <version>0.0.1-SNAPSHOT</version> 
      <packaging>war</packaging> 
      <parent> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-parent</artifactId> 
       <version>1.3.3.RELEASE</version> 
       <relativePath /> <!-- lookup parent from repository --> 
      </parent> 
      <properties> 
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
       <java.version>1.7</java.version> 
      </properties> 
      <dependencies> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-data-jpa</artifactId> 
        <exclusions> 
         <exclusion> 
          <artifactId>hibernate-entitymanager</artifactId> 
          <groupId>org.hibernate</groupId> 
         </exclusion> 
        </exclusions> 
       </dependency> 
       <dependency> 
        <groupId>mysql</groupId> 
        <artifactId>mysql-connector-java</artifactId> 
        <version>5.1.38</version> 
       </dependency> 
       <dependency> 
        <groupId>com.zaxxer</groupId> 
        <artifactId>HikariCP</artifactId> 
        <version>2.4.5</version> 
       </dependency> 
       <dependency> 
        <groupId>com.fasterxml.jackson.dataformat</groupId> 
        <artifactId>jackson-dataformat-xml</artifactId> 
       </dependency> 
        <dependency> 
       <groupId>org.codehaus.woodstox</groupId> 
       <artifactId>woodstox-core-asl</artifactId> 
       <version>4.4.1</version> 
      </dependency> 
       <dependency> 
        <groupId>org.eclipse.persistence</groupId> 
        <artifactId>eclipselink</artifactId> 
        <version>2.6.2</version> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-data-rest</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-security</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-data-jpa</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-cache</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.mobile</groupId> 
        <artifactId>spring-mobile-device</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-web</artifactId> 
        <exclusions> 
         <exclusion> 
          <groupId>org.springframework.boot</groupId> 
          <artifactId>spring-boot-starter-tomcat</artifactId> 
         </exclusion> 
        </exclusions> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-undertow</artifactId> 
         <scope>provided</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-mail</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-actuator</artifactId> 
       </dependency> 
       <dependency> 
        <groupId>com.h2database</groupId> 
        <artifactId>h2</artifactId> 
        <scope>runtime</scope> 
       </dependency> 
       <dependency> 
        <groupId>io.jsonwebtoken</groupId> 
        <artifactId>jjwt</artifactId> 
        <version>0.6.0</version> 
       </dependency> 
       <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-test</artifactId> 
        <scope>test</scope> 
       </dependency> 
       <dependency> 
        <groupId>org.xerial</groupId> 
        <artifactId>sqlite-jdbc</artifactId> 
        <version>3.8.11.2</version> 
       </dependency> 
       <!-- http://mvnrepository.com/artifact/com.nativelibs4java/bridj --> 
       <dependency> 
        <groupId>com.nativelibs4java</groupId> 
        <artifactId>bridj</artifactId> 
        <version>0.7.0</version> 
       </dependency> 
       <!-- Apache FOP --> 
       <dependency> 
        <groupId>org.apache.xmlgraphics</groupId> 
        <artifactId>fop</artifactId> 
        <version>2.1</version> 
       </dependency> 
       <!-- Apache PDFBox --> 
       <dependency> 
        <groupId>org.apache.pdfbox</groupId> 
        <artifactId>pdfbox</artifactId> 
        <version>2.0.1</version> 
       </dependency> 
       <dependency> 
        <groupId>org.apache.commons</groupId> 
        <artifactId>commons-configuration2</artifactId> 
        <version>2.0</version> 
       </dependency> 
       <dependency> 
        <groupId>commons-fileupload</groupId> 
        <artifactId>commons-fileupload</artifactId> 
        <version>1.3.2</version> 
       </dependency> 
       <!-- http://mvnrepository.com/artifact/org.freemarker/freemarker --> 
       <dependency> 
        <groupId>org.freemarker</groupId> 
        <artifactId>freemarker</artifactId> 
        <version>2.3.23</version> 
       </dependency> 
       <!-- https://mvnrepository.com/artifact/com.google.guava/guava --> 
       <dependency> 
        <groupId>com.google.guava</groupId> 
        <artifactId>guava</artifactId> 
        <version>19.0</version> 
       </dependency> 
       <dependency> 
        <groupId>net.sf.ehcache</groupId> 
        <artifactId>ehcache</artifactId> 
       </dependency> 
      </dependencies> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-maven-plugin</artifactId> 
        </plugin> 
       </plugins> 
      </build> 
      <repositories> 
       <repository> 
        <id>maven2-repository.dev.java.net</id> 
        <name>Java.net repository</name> 
        <url>http://download.java.net/maven/2</url> 
       </repository> 
      </repositories> 
     </project> 

您可以粘貼您的pom.xml文件。

+0

pdfbox現在在2.0.4。 (與答案無關,但可能與您有關) –

+0

Subhasish Sahu,我在上面的帖子中添加了我的pom.xml。 –

+0

@Syrine - 你可以粘貼你的pom.xml嗎 –

0

@Syrine

因爲我沒有你的孩子的項目,我已經合併雙方pom.xml文件內容到一個和它運行得很好,我local.Please你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/xsd/maven-4.0.0.xsd"> 
       <modelVersion>4.0.0</modelVersion> 
       <groupId>com.subu</groupId> 
       <artifactId>SpringBootExamples</artifactId> 
       <version>0.0.1-SNAPSHOT</version> 
       <packaging>war</packaging> 
       <parent> 
        <groupId>io.spring.platform</groupId> 
        <artifactId>platform-bom</artifactId> 
        <version>2.0.1.RELEASE</version> 
       </parent> 
       <properties> 
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
        <java.version>1.7</java.version> 
       </properties> 
       <repositories> 
        <repository> 
         <id>vaadin-addons</id> 
         <url>http://maven.vaadin.com/vaadin-addons</url> 
         <snapshots> 
          <enabled>true</enabled> 
         </snapshots> 
        </repository> 
       </repositories> 
       <dependencies> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-devtools</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter-data-jpa</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter-jdbc</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>com.vaadin</groupId> 
         <artifactId>vaadin-spring-boot-starter</artifactId> 
         <version>1.0.1</version> 
        </dependency> 
        <dependency> 
         <groupId>org.postgresql</groupId> 
         <artifactId>postgresql</artifactId> 
         <scope>runtime</scope> 
        </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> 
         <scope>test</scope> 
        </dependency> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter-web</artifactId> 
         <exclusions> 
          <exclusion> 
           <groupId>org.springframework.boot</groupId> 
           <artifactId>spring-boot-starter-tomcat</artifactId> 
          </exclusion> 
         </exclusions> 
        </dependency> 
        <dependency> 
         <groupId>com.google.guava</groupId> 
         <artifactId>guava</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>com.vaadin.tapio</groupId> 
         <artifactId>googlemaps</artifactId> 
         <version>1.3.4</version> 
        </dependency> 
        <dependency> 
         <groupId>commons-beanutils</groupId> 
         <artifactId>commons-beanutils</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>commons-collections</groupId> 
         <artifactId>commons-collections</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>org.freemarker</groupId> 
         <artifactId>freemarker</artifactId> 
        </dependency> 
        <dependency> 
         <groupId>mysql</groupId> 
         <artifactId>mysql-connector-java</artifactId> 
         <version>5.1.38</version> 
        </dependency> 
        <dependency> 
         <groupId>com.zaxxer</groupId> 
         <artifactId>HikariCP</artifactId> 
         <version>2.4.5</version> 
        </dependency> 
        <dependency> 
         <groupId>com.fasterxml.jackson.dataformat</groupId> 
         <artifactId>jackson-dataformat-xml</artifactId> 
        </dependency> 
         <dependency> 
        <groupId>org.codehaus.woodstox</groupId> 
        <artifactId>woodstox-core-asl</artifactId> 
        <version>4.4.1</version> 
       </dependency> 
        <dependency> 
         <groupId>org.eclipse.persistence</groupId> 
         <artifactId>eclipselink</artifactId> 
         <version>2.6.2</version> 
        </dependency> 
        <dependency> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter-security</artifactId> 
        </dependency> 
       </dependencies> 
       <!-- <modules> 
        <module>flexedge-css</module> 
        <module>flexedge-css-ejb</module> 
        <module>flexedge-cssadmin</module> 
       </modules> --> 
       <dependencyManagement> 
        <dependencies> 
         <dependency> 
          <groupId>com.vaadin</groupId> 
          <artifactId>vaadin-bom</artifactId> 
          <version>7.7.3</version> 
          <type>pom</type> 
          <scope>import</scope> 
         </dependency> 
        </dependencies> 
       </dependencyManagement> 

       <build> 
        <plugins> 
         <plugin> 
          <groupId>org.springframework.boot</groupId> 
          <artifactId>spring-boot-maven-plugin</artifactId> 
         </plugin> 
        </plugins> 
       </build> 
      </project> 
相關問題