2017-04-07 124 views
2

我有一个使用spring引导创建的现有战争项目。如何将它打包在具有EJB模块的EAR中?在EAR项目中集成Spring Boot

有什么办法可以将模型和dao包移动到EJB模块并注入WAR模块吗?

回答

0

你必须使用的依赖关系管理系统。

它允许您将Spring Boot WAR模块项目的父项设置为与spring-boot-starter-parent不同。然后就可以将WAR项目纳入EAR之中,就像其他项目一样。

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <!-- Import dependency management from Spring Boot --> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-dependencies</artifactId> 
      <version>1.5.2.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

...现在你可以使用所有的春季启动启动依赖于通常的方式:

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
    </dependency> 
</dependencies> 

起动依赖你已经指定在模块项目的水平,而依赖管理可以在两个项目中指定配置 - 在整个EAR项目中或在每个项目上单独指定,具体取决于应用程序要求。

Using Spring Boot without the parent POM

2

您需要一个父项目,其中包括一个战争项目,这是您的春季启动项目,和一个耳朵项目只是让你耳朵。

家长需要有春天启动它的父:

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

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.3.RELEASE</version> 
    </parent> 

    <groupId>com.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <properties> 
     <myproject.version>1.0-SNAPSHOT</myproject.version> 
    </properties> 

    <name>ear-example</name> 
    <modules> 
    <module>example-ear</module> 
    <module>example-war</module> 
    </modules> 

</project> 

你的耳朵的项目是:

<?xml version="1.0"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <groupId>com.greg</groupId> 
    <artifactId>ear-example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>example-ear</artifactId> 
    <packaging>ear</packaging> 

    <dependencies> 
    <dependency> 
     <groupId>com.greg</groupId> 
     <artifactId>example-war</artifactId> 
     <version>${project.version}</version> 
     <type>war</type> 
    </dependency> 
    </dependencies> 

    <build> 
    <plugins> 
    <plugin> 
     <artifactId>maven-ear-plugin</artifactId> 
     <version>2.10.1</version> 
     <configuration> 
       <modules> 
         <webModule> 
           <groupId>com.greg</groupId> 
           <artifactId>example-war</artifactId> 
           <contextRoot>/appname</contextRoot> 
         </webModule> 
       </modules> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

</project> 
相关问题