2016-10-06 115 views
0

我想使用彈簧引導來建立jar作爲更大的項目的一部分,這意味着我已經定義了<parentID>部分。現在我必須以某種方式插入springboot到我的項目,這是我想出了:使用Maven與春季啓動 - parentID

<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> 

    <parent> 
     <artifactId>spageeserver</artifactId> 
     <groupId>com.spagee</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 

    <groupId>com.spagee</groupId> 
    <artifactId>persistence</artifactId> 
    <name>persistence</name> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 


    <dependencies> 
     <dependency> 
      <!-- Import dependency management from Spring Boot --> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-dependencies</artifactId> 
      <version>1.4.1.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-data-jpa</artifactId> 
      <version>1.4.1.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-jdbc</artifactId> 
      <version>1.4.1.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
      <version>1.4.1.RELEASE</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <version>1.4.1.RELEASE</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.h2database</groupId> 
      <artifactId>h2</artifactId> 
      <version>1.4.192</version> 
     </dependency> 
     <dependency> 
      <groupId>org.postgresql</groupId> 
      <artifactId>postgresql</artifactId> 
      <version>9.4.1208.jre7</version> 
     </dependency> 
    </dependencies> 
</project> 

,但該項目將無法啓動:

2016-10-06 16:07:43.264[0;39m [32m INFO[0;39m [35m5296[0;39m [2m---[0;39m [2m[   main][0;39m [36mationConfigEmbeddedWebApplicationContext[0;39m [2m:[0;39m Closing org.springframework.boot[email protected]74fe5c40: startup date [Thu Oct 06 16:07:41 CEST 2016]; root of context hierarchy 
[2m2016-10-06 16:07:43.264[0;39m [33m WARN[0;39m [35m5296[0;39m [2m---[0;39m [2m[   main][0;39m [36mationConfigEmbeddedWebApplicationContext[0;39m [2m:[0;39m Exception thrown from LifecycleProcessor on context close 

java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot[email protected]74fe5c40: startup date [Thu Oct 06 16:07:41 CEST 2016]; root of context hierarchy 
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:415) [spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:975) [spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:934) [spring-context-4.2.8.RELEASE.jar:4.2.8.RELEASE] 
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:818) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] 
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE] 
    at com.spagee.Runner.main(Runner.java:13) [classes/:na] 

以前用「的parentID」設置爲春季開機一切正常。所以這是一個POM水平問題

主要POM

<?xml version="1.0" encoding="UTF-8"?> 
<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.spagee</groupId> 
    <artifactId>spageeserver</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <modules> 
     <module>facebookgrabber</module> 
     <module>persistence</module> 
    </modules> 


</project> 
+0

你的主要樣子是什麼? –

+0

這可以幫助:[可以maven項目有多個父母嗎?](http://stackoverflow.com/questions/1636801/can-maven-projects-have-multiple-parents) –

回答

0

將彈簧引導設置爲您的主pom的父級。

0

嘗試把依賴於彈簧引導依賴dependencyManagement下,而不是直接下的依賴。