Search code examples
springspring-bootear

Integrate Spring Boot in an EAR project


I have an existing war project created using spring boot. How to package it within an EAR which has an EJB module?

Is there any way to move the model and dao packages to EJB module and injecting it with WAR module?


Solution

  • You have to use the dependency management system.

    It allows you to set the parent of a Spring Boot WAR module project that is different from spring-boot-starter-parent. It would make it possible to include the WAR project into EAR in the same way just like any other.

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

    ... then you would use starter dependencies in the usual way:

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

    Shared dependencies may be specified by the root level pom while the individual ones might be a module bounded.

    Using Spring Boot without the parent POM