1

Here is my project structure :

enter image description here

I have two spring-boot modules. In auth module I implement spring security. And I have Auth controller that allows us to sign up and sign in(returns jwt token). In account-management module I want to get user profile and I should use auth module. I should have different databases.

Here is my parent pom :

 <groupId>com.social.network</groupId>
<artifactId>social-network</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>social-network-auth</module>
    <module>social-network-account-management</module>
</modules>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<build>
    <pluginManagement>
        <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>
    </pluginManagement>
</build>

Here is auth module's pom :

    <groupId>com.social.network.auth</groupId>
    <artifactId>social-network-auth</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>social-network-auth</name>
    <description>Authentication module for SocialNetwork</description>

    <parent>
        <groupId>com.social.network</groupId>
        <artifactId>social-network</artifactId>
        <version>1.0-SNAPSHOT</version>
        <!--<relativePath>../pom.xml</relativePath>-->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <jwt.version>0.6.0</jwt.version>
        <swagger.version>2.7.0</swagger.version>
    </properties>

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

And here is my account-management's pom

<groupId>com.social.network.account.management</groupId>
<artifactId>social-network-account-management</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>social-network-account-management</name>
<description>Account management module for SocialNetwork</description>

<parent>
    <groupId>com.social.network</groupId>
    <artifactId>social-network</artifactId>
    <version>1.0-SNAPSHOT</version>
    <!--<relativePath>../pom.xml</relativePath>-->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.social.network.auth</groupId>
        <artifactId>social-network-auth</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>


</dependencies>

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

I want to run all my modules.

enter image description here

But build fails. I am getting Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project egs-social-network: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

dur
  • 15,689
  • 25
  • 79
  • 125
Lilit Mkrtchyan
  • 135
  • 1
  • 2
  • 11

2 Answers2

1

First of all you should understand that two different application could not be running on the same port. So you thought in the right way, but the main goal is to separate logical parts to different modules, my congatulations, you have already done it. So now, just make the right dependency chain. (child -> parent!) And also the child module could not be a spring boot application. It could be some kind of additional sets of classes or library for your main module. And please read the answer How to make one module depend on another module artifact?. You can have multiply controllers in one application, but with different mappings, you don't need for this purposes two different applications. By the way, first off all please run mvn package and install =)

0

You have to call

mvn spring-boot:run 

in each module to run the applications.

You find the goal under "Plugins".

But as you are using IntelliJ there is a Spring Boot Run Dashboard where you can run all applications.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
  • I want to run them in the same port. – Lilit Mkrtchyan Sep 01 '18 at 11:19
  • I have controllers in both modules and they should be availabel from client. Eg. http://localhost:8080/api/v1/auth/signup, http://localhost:8080/api/v1/auth/signin from auth module, and http://localhost:8080/api/v1/account/ from account-management module (this one should provide token returned from signin endpoint) – Lilit Mkrtchyan Sep 01 '18 at 11:36
  • 1
    The your approach is wrong. You must create on spring boot application and then add the other modules as dependencies. But these modules are not spring boot applications. – Simon Martinelli Sep 02 '18 at 08:48