Java 多模块spring引导配置

Java 多模块spring引导配置,java,spring,maven,spring-boot,Java,Spring,Maven,Spring Boot,我正在尝试配置多模块Spring引导应用程序。最简单的例子是: pom1 为什么我在启动maven'clean spring boot:run'时出错 "C:\Program Files\Java\jdk1.8.0_102\bin\java" -Dmaven.multiModuleProjectDirectory=D:\PROGRAMACION\Projects\TEMP_PROJECTS\testExample "-Dmaven.home=C:\Program Files (x86)\Jet

我正在尝试配置多模块Spring引导应用程序。最简单的例子是:

pom1

为什么我在启动maven'clean spring boot:run'时出错

"C:\Program Files\Java\jdk1.8.0_102\bin\java" -Dmaven.multiModuleProjectDirectory=D:\PROGRAMACION\Projects\TEMP_PROJECTS\testExample "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\lib\idea_rt.jar=57646:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.1 clean spring-boot:run
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] testExample
[INFO] module1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building testExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ testExample ---
[INFO] 
[INFO] >>> spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) > test-compile @ testExample >>>
[INFO] 
[INFO] <<< spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) < test-compile @ testExample <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) @ testExample ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] testExample ........................................ FAILURE [  0.487 s]
[INFO] module1 ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.884 s
[INFO] Finished at: 2017-03-25T16:44:47+02:00
[INFO] Final Memory: 18M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project testExample: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1
“C:\Program Files\Java\jdk1.8.0\u 102\bin\Java”-Dmaven.multimulticuleprojectdirectory=D:\PROGRAMACION\Projects\TEMP\Projects\testExample”-Dmaven.home=C:\Program Files(x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3”“-dclasswords.conf=C:\Program Files(x86)\JetBrains\IntelliJ IDEA 2017.1\maven\maven3\bin\m2.conf”“-javaagent:C:\Program Files(x86)\JetBrains\IntelliJ IDEA 2017.1\lib\IDEA\u rt.jar=57646:C:\Program Files(x86)\JetBrains\IntelliJ IDEA 2017.1\bin”-Dfile.encoding=UTF-8-classpath”C:\Program Files(x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar“org.codehaus.classworlds.Launcher-Didea.version=2017.1 clean spring启动:运行
[信息]正在扫描项目。。。
[信息]------------------------------------------------------------------------
[信息]反应堆建造顺序:
[信息]
[信息]测试示例
[信息]模块1
[信息]
[信息]------------------------------------------------------------------------
[信息]构建测试示例1.0-SNAPSHOT
[信息]------------------------------------------------------------------------
[信息]
[信息]---maven clean插件:2.6.1:clean(默认清洁)@testExample---
[信息]
[信息]>>>spring boot maven插件:1.5.2.版本:运行(默认cli)>测试编译@testExample>>>
[信息]

[INFO]
mvn clean spring boot:run
必须从包含
SpringBoot应用程序的模块执行
您可以从父pom执行它。

模块1
执行此命令,它应该可以工作

顺便说一下,
module1
pom.xml中的重复声明不是必需的,因为您的家长已经指定了它:

 <build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

maven编译器插件
3.1
1.8
1.8
我就是这样做的

从多模块项目的根目录运行以下命令:

mvn -pl module1 spring-boot:run
现在,如果在多模块spring boot项目的根目录中有一个
config
文件夹,spring boot还将扫描该文件夹中的属性文件(src/main/resources除外),使这些属性对所有模块都是全局的

"C:\Program Files\Java\jdk1.8.0_102\bin\java" -Dmaven.multiModuleProjectDirectory=D:\PROGRAMACION\Projects\TEMP_PROJECTS\testExample "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\lib\idea_rt.jar=57646:C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2017.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.1 clean spring-boot:run
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] testExample
[INFO] module1
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building testExample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ testExample ---
[INFO] 
[INFO] >>> spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) > test-compile @ testExample >>>
[INFO] 
[INFO] <<< spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) < test-compile @ testExample <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) @ testExample ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] testExample ........................................ FAILURE [  0.487 s]
[INFO] module1 ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.884 s
[INFO] Finished at: 2017-03-25T16:44:47+02:00
[INFO] Final Memory: 18M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:run (default-cli) on project testExample: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1
 <build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
mvn -pl module1 spring-boot:run