wake-up-neo.com

Spring Boot: Ausführen eines Multi-Modul-Projekts

Ich habe eine grundlegende SpringBoot-App. Spring Initializer, Embedded Tomcat, Thymeleaf Template Engine und Package als ausführbare JAR-Datei verwenden ist ein Multimodul-Projekt mit Spring Boot, das Projekt wird 3 Module haben. Das Elternmodul pom.xml

<?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.5.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.tdkcloud</groupId>
    <artifactId>tdk-cloud</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>   
        <module>tdk-core</module>
        <module>tdk-batch</module>
        <module>tdk-web</module>
    </modules>


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

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>uk.co.jemos.podam</groupId>
            <artifactId>podam</artifactId>
            <version>7.0.5.RELEASE</version>
            <scope>test</scope>
        </dependency>


        <!-- Logging dependencies -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>

        <!-- Email dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <!-- Security dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <!-- Spring data -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>



    </dependencies>

</project>

Hier der Modulkern

<?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.tdkcloud</groupId>
        <artifactId>tdk-cloud</artifactId>
        <version>0.0.2-SNAPSHOT</version>
    </parent>


  <groupId>com.tdkcloud.core</groupId>
  <artifactId>tdk-core</artifactId>
   <packaging>jar</packaging>    



  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <Java.version>1.8</Java.version>
  </properties>

  <dependencies>


        <!--  Hibernate dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>

        <dependency>
            <groupId>com.googlecode.libphonenumber</groupId>
            <artifactId>libphonenumber</artifactId>
            <version>8.4.3</version>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <!-- <version>1.10</version> -->
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <!-- <version>2.9.0.pr3</version> -->
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <!-- <version>2.9.0.pr3</version> -->
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>       
        </dependency>

        <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.9</version>
</dependency>


    </dependencies>

</project>

und hier das Modul web:

<?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.tdkcloud</groupId>
        <artifactId>tdk-cloud</artifactId>
        <version>0.0.2-SNAPSHOT</version>
    </parent>

  <groupId>com.tdkcloud.web</groupId>
  <artifactId>tdk-web</artifactId>
  <packaging>jar</packaging>


  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <Java.version>1.8</Java.version>
    <start-class>com.tdkcloud.TdkCloudApplication</start-class>
  </properties>

  <dependencies>

        <!-- tdk-core dependencies -->
         <dependency>
            <groupId>com.tdkcloud.core</groupId>
            <artifactId>tdk-core</artifactId>
            <version>0.0.2-SNAPSHOT</version>           
        </dependency> 

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>


        <!-- Webjars for JQuery and Bootstrap -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7-1</version>
        </dependency> 
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.2.0</version>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
            <!-- <version>3.0.2.RELEASE</version> -->
        </dependency>


   </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.Apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.tdkcloud.TdkCloudApplication</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>  

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


</project>

von der übergeordneten Wurzel generiere ich alle Module mit:

mvn clean package

Das Problem ist jedoch, dass der tdk-web-0.0.2-SNAPSHOT.jar den tdk-core-0.0.2-SNAPSHOT.jar nicht enthält und beim Start fehlschlägt

Hier das Maven-Ergebnis:

MacBook-Pro-de-nunito:tdk-cloud calzada$ mvn clean package -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] tdk-cloud
[INFO] tdk-core
[INFO] tdk-batch
[INFO] tdk-web
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building tdk-cloud 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ tdk-cloud ---
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building tdk-core 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.h2database:h2:jar:1.4.194 is missing, no dependency information available
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ tdk-core ---
[INFO] Deleting /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-core/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ tdk-core ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ tdk-core ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 52 source files to /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-core/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ tdk-core ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ tdk-core ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ tdk-core ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ tdk-core ---
[INFO] Building jar: /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-core/target/tdk-core-0.0.2-SNAPSHOT.jar
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building tdk-batch 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ tdk-batch ---
[INFO] Deleting /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-batch/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ tdk-batch ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-batch/src/main/resources
[INFO] skip non existing resourceDirectory /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-batch/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ tdk-batch ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-batch/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ tdk-batch ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ tdk-batch ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ tdk-batch ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ tdk-batch ---
[INFO] Building jar: /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-batch/target/tdk-batch-0.0.2-SNAPSHOT.jar
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building tdk-web 0.0.2-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ tdk-web ---
[INFO] Deleting /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-web/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ tdk-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 339 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ tdk-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 25 source files to /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-web/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ tdk-web ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ tdk-web ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ tdk-web ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ tdk-web ---
[INFO] Building jar: /Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/tdk-cloud/tdk-web/target/tdk-web-0.0.2-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.3.RELEASE:repackage (default) @ tdk-web ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] tdk-cloud ....................................... SUCCESS [  0.105 s]
[INFO] tdk-core ........................................ SUCCESS [  1.634 s]
[INFO] tdk-batch ....................................... SUCCESS [  0.114 s]
[INFO] tdk-web ......................................... SUCCESS [  1.506 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.663 s
[INFO] Finished at: 2017-05-30T05:37:04+02:00
[INFO] Final Memory: 47M/539M
[INFO] ------------------------------------------------------------------------
MacBook-Pro-de-nunito:tdk-cloud calzada$ 

Dies ist der Fehler, den ich bekam:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field emailService in com.tdkcloud.web.controllers.AppErrorController required a bean of type 'com.tdkcloud.backend.service.EmailService' that could not be found.


Action:

Consider defining a bean of type 'com.tdkcloud.backend.service.EmailService' in your configuration.

Ich habe das Glas entpackt und es gibt keine Klasse des Kernmoduls

hinzufügen des vorgeschlagenen Codes zum Modul Web:

<plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Ich habe den nächsten Fehler: Error resolving template "/tdk/login/login", template might not exist or might not be accessible by any of the configured Template Reso 

aber die Vorlage ist da:  enter image description here

Vor kurzem habe ich versucht, eines meiner Projektstrukturen/Layouts als Maven-Multi-Modul-Projekt zu implementieren. 

Ich folgte dem folgenden Spring Guide-Link. Ich hoffe, das hilft Ihnen und anderen Official Spring Multi Module Project Link

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <executable>true</executable>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Ich empfehle dies zum Erstellen eines ausführbaren Jar.

2
ahll

Ich denke, Ihre @ComponentScan-Anmerkung fehlt oder ist möglicherweise falsch. (z. B .: @ComponentScan ({"com.tdkcloud.web"}) kann keine Dienste im Paket com.tdkcloud.backend finden. Oder vielleicht fehlt die @Service-Anmerkung in Ihrem EmailService. 

Um dies zu lösen, muss Ihr Code ungefähr so ​​aussehen: 

App.Java (oder Webconfig.Java)

@Configuration
@EnableWebMvc
@ComponentScan({"com.tdkcloud"})
@SpringBootApplication
public class App {
   ...
}

EmailService.Java

public interface EmailService {
   ...
}

EmailServiceImpl.Java

@Service
public class EmailServiceImpl {
   ...
}
1
Jack

sie fehlen version im Kernmodul. Versuchen Sie, das folgende Kernmodul pom hinzuzufügen

<version>0.0.2-SNAPSHOT</version>

so wird es.

<groupId>com.tdkcloud.core</groupId>
<artifactId>tdk-core</artifactId>
<packaging>jar</packaging> 
<version>0.0.2-SNAPSHOT</version> 
0
Jobin Joseph

Spring Boot benötigt eine Bean vom Typcom.tdkcloud.backend.service.EmailServiceund findet sie nicht. Du hast eine Lösung: 

1 - Erste Lösung: Erstellen Sie die Bean in Ihrer Anwendung folgendermaßen:

@Bean
public EmailService EmailService() {
    return new com.tdkcloud.backend.service.EmailServiceImpl();
}

2 - Zweite Lösung: Use @ComponentScan wie folgt:

@ComponentScan(basePackages = {"com.tdkcloud.backend.service.EmailService"})
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

ANMERKUNG: In Ihrem Paket com.tdkcloud.backend.service.EmailService ist eine Frühjahrskennzeichnung erforderlich. 

0
Jacob

Versuchen Sie, dies hinzuzufügen.

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

Repaketiert vorhandene JAR- und WAR-Archive so, dass sie von der Befehlszeile aus mit Java-Jar ausgeführt werden können. Mit layout = NONE kann auch einfach eine JAR mit geschachtelten Abhängigkeiten (und keiner Hauptklasse, also nicht ausführbar) gepackt werden.

Bekam aus das

0
StanislavL

Ich war früher mit demselben Problem konfrontiert. Ich vermute, Sie lassen das Glas nicht in der Explosionsform laufen. Sie benötigen dieses Plugin wahrscheinlich, um die Gläser in das Bundle zu ziehen und das Original-Original auszuführen.

               <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>install</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Dadurch werden alle Abhängigkeiten gebündelt, die Sie in Ihrem Pom innerhalb des Tiegels definiert haben. Hoffe das hilft.

0
Sadiq Ali