Maven Multi Module Spring Boot Project

I am trying to create a multi-module project containing two modules, core and networking. These are both Spring Boot projects that I created on Spring Initialzer. I am setting up MOV Maven files, but I am having trouble deploying it. However, I am confused about how the config would work.

The main module will contain domain object / entities, data stores, w760> Data JPA services and will be packaged as JAR. The web module will have Spring Security, controllers and views. It will be packaged as WAR.

The normal structure of a Spring Boot project is as follows

/
pom.xml
src/
..main/
....com/
......example/
........app/
..........Application.java
..resources/
....application.properites

      

I essentially have two of these and two Spring Boot / configuration / initialization classes.

My questions

  • Should the properties live in the same config file or do I have two application.properities properties, one for the core and one for the WAR?

  • May I have the following in my core.jar

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication
    public class TimesheetCoreApplication {
    
      public static void main(String[] args) {
        SpringApplication.run(TimesheetCoreApplication.class, args);
      }
    }
    
          

Along with the following two in my web.war

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TimesheetWebApplication {

    public static void main(String[] args) {
        SpringApplication.run(TimesheetWebApplication.class, args);
    }
}

      

and

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TimesheetWebApplication.class);
    }

}

      

  1. Since Spring Boot does a lot of automatic configuration, will they flow over each other with configuration conflicting or overriding each other?

What is the best way to approach this? I would like to use Spring Boot if possible.

+3


source to share


3 answers


your design is a little flawed, if your main project will have domain objects, repos, etc. it shouldn't be a BOOT application. As you said, it will be Jar.

Now you make your web application a bootable application with a kernel cube dependency. You can define .properties or .yml in a bootable application and you're good to go.

The problem with Spring Initializer is that it looks like all the code should be in the same project or module.



This is a typical project I do for my applications

  • project-core-module (Jar packaging -> domain objects, repositories, etc.)
  • project-service-module (boot -> config, rest interface, security, etc.)
  • project-system-tests (run at compile time and validate the build)

Now you link the kernel and system module to the service module as a dependency.

+2


source


Please find the answers to your questions.

1. Should the properties work in the same config file or do I have two application.properities properties, one for the kernel and one for the WAR?

Both of them cannot be named application.properties

. Post my answer to this question here .

2. Can I have the following in my core.jar

Yes you can if you follow the steps in the link.



3. Since Spring Boot does a lot of automatic configuration, will they flow over each other with configuration conflicting or overriding each other?

You will only download one app at a time. Let's say if you are using an app TimesheetWebApplication

then TimesheetCoreApplication

it won't load. The time TimesheetCoreApplication

will only be included as a regular JAR.

Alternatively, you can also do the following

  • Put yours TimesheetCoreApplication

    as follows. Refer here . This will ensure that every time you do a maven install, a jar is installed for the repo, which will contain only the class files (no tomcat built-in libraries).

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                      <execution>
                        <goals>
                          <goal>repackage</goal>
                        </goals>
                        <configuration>
                          <classifier>exec</classifier>
                        </configuration>
                      </execution>
                    </executions>
                </plugin>
            </plugins>
    
          

+1


source


Short,

  • You don't need .properties, you can use yaml with spring boot, this is more readable. The yaml file is sufficient for your configuration, because yaml uses indentation, so you can easily distinguish between options.

  • The Single Application class is great because you won't be executing just the main module.

  • There are many starter dependencies and their configurations , you can speed up your projects.

0


source







All Articles