本来不打算写这一篇的,但是在操作过程中,创建了几次都无法在同一个窗口中正常启动多个子模块,启动类无法识别。所以就再次记录一下。由于我本地已经搭建成功,所以本篇是另开工作目录来创建,主要是为了重现搭建过程和一些细节。后面的gitee上传的是真正的项目。
maven管理子模块,主要是为了统一管理版本和通用的jia报,以及微服务模块之间的抽离和封装。也方便我们对整个项目的管理。其他就不多说了,大家也都知道。
设置maven
我们先做好maven配置,在idea中,File-->Settings
在settings.xml中,我们修改两个地方:
1、设置自己maven仓库位置,默认是C盘
在localRepository节点中修改自己想存放的位置(这里存放的是项目依赖的jar包)
<localRepository>D:\Tools\maven_repo</localRepository>
1、修改仓库源
在mirrors节点中添加
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
注:这样设置我发现每开一个工作空间,都要重新设置,下面我们来设置下默认的maven配置,这样以后每次新开窗口也不用在重新设置。
这样新建项目或打开新的窗口,都将使用这里所配置的maven配置。
创建父项目
作为示例项目,创建项目名为demo的maven项目
创建完成:
创建子模块 module1
项目右键
我们的子模块是Spring Boot 类型
我们启动Module1Application,打开类,直接右键
"C:\Program Files\Java\jdk1.8.0_111\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:61354,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\back_\AppData\Local\JetBrains\IntelliJIdea2020.1\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_111\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_111\jre\lib\rt.jar;D:\ProjectWork\demo\demo\module1\target\classes;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter-web\2.2.6.RELEASE\spring-boot-starter-web-2.2.6.RELEASE.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter\2.2.6.RELEASE\spring-boot-starter-2.2.6.RELEASE.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot\2.2.6.RELEASE\spring-boot-2.2.6.RELEASE.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-autoconfigure\2.2.6.RELEASE\spring-boot-autoconfigure-2.2.6.RELEASE.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter-logging\2.2.6.RELEASE\spring-boot-starter-logging-2.2.6.RELEASE.jar;D:\Tools\maven_repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\Tools\maven_repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\Tools\maven_repo\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;D:\Tools\maven_repo\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;D:\Tools\maven_repo\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\Tools\maven_repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\Tools\maven_repo\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter-json\2.2.6.RELEASE\spring-boot-starter-json-2.2.6.RELEASE.jar;D:\Tools\maven_repo\com\fasterxml\jackson\core\jackson-databind\2.10.3\jackson-databind-2.10.3.jar;D:\Tools\maven_repo\com\fasterxml\jackson\core\jackson-annotations\2.10.3\jackson-annotations-2.10.3.jar;D:\Tools\maven_repo\com\fasterxml\jackson\core\jackson-core\2.10.3\jackson-core-2.10.3.jar;D:\Tools\maven_repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.3\jackson-datatype-jdk8-2.10.3.jar;D:\Tools\maven_repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.3\jackson-datatype-jsr310-2.10.3.jar;D:\Tools\maven_repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.3\jackson-module-parameter-names-2.10.3.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter-tomcat\2.2.6.RELEASE\spring-boot-starter-tomcat-2.2.6.RELEASE.jar;D:\Tools\maven_repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.33\tomcat-embed-core-9.0.33.jar;D:\Tools\maven_repo\org\apache\tomcat\embed\tomcat-embed-el\9.0.33\tomcat-embed-el-9.0.33.jar;D:\Tools\maven_repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.33\tomcat-embed-websocket-9.0.33.jar;D:\Tools\maven_repo\org\springframework\boot\spring-boot-starter-validation\2.2.6.RELEASE\spring-boot-starter-validation-2.2.6.RELEASE.jar;D:\Tools\maven_repo\jakarta\validation\jakarta.validation-api\2.0.2\jakarta.validation-api-2.0.2.jar;D:\Tools\maven_repo\org\hibernate\validator\hibernate-validator\6.0.18.Final\hibernate-validator-6.0.18.Final.jar;D:\Tools\maven_repo\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;D:\Tools\maven_repo\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\Tools\maven_repo\org\springframework\spring-web\5.2.5.RELEASE\spring-web-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-beans\5.2.5.RELEASE\spring-beans-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-webmvc\5.2.5.RELEASE\spring-webmvc-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-aop\5.2.5.RELEASE\spring-aop-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-context\5.2.5.RELEASE\spring-context-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-expression\5.2.5.RELEASE\spring-expression-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\Tools\maven_repo\org\springframework\spring-core\5.2.5.RELEASE\spring-core-5.2.5.RELEASE.jar;D:\Tools\maven_repo\org\springframework\spring-jcl\5.2.5.RELEASE\spring-jcl-5.2.5.RELEASE.jar;D:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar" com.demo.module1.Module1Application
Connected to the target VM, address: '127.0.0.1:61354', transport: 'socket'
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-04 10:41:19.688 INFO 2064 --- [ main] com.demo.module1.Module1Application : Starting Module1Application on DESKTOP-MBI0KTI with PID 2064 (D:\ProjectWork\demo\demo\module1\target\classes started by wei in D:\ProjectWork\demo\demo)
2020-05-04 10:41:19.692 INFO 2064 --- [ main] com.demo.module1.Module1Application : No active profile set, falling back to default profiles: default
2020-05-04 10:41:20.292 INFO 2064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-04 10:41:20.299 INFO 2064 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-04 10:41:20.299 INFO 2064 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-04 10:41:20.356 INFO 2064 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-04 10:41:20.357 INFO 2064 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 628 ms
2020-05-04 10:41:20.465 INFO 2064 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-04 10:41:20.590 INFO 2064 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-04 10:41:20.593 INFO 2064 --- [ main] com.demo.module1.Module1Application : Started Module1Application in 1.232 seconds (JVM running for 3.856)
启动成功,在主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>
<groupId>org.demo</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>module1</module>
</modules>
</project>
在 Terminal执行mvn clean package ,出现错误:
-
D:\ProjectWork\demo\demo>mvn package [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project org.demo:demo:1.0-SNAPSHOT (D:\ProjectWork\demo\demo\pom.xml) has 1 error [ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109 [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/ProjectBuildingException
在主pom文件中添加:
<packaging>pom</packaging>
在子模块pom中添加:
<packaging>jar</packaging>
再次执行,即可成功:
D:\ProjectWork\demo\demo>mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] module1 [jar]
[INFO] demo [pom]
[INFO]
[INFO] --------------------------< com.demo:module1 >--------------------------
[INFO] Building module1 0.0.1-SNAPSHOT [1/2]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ module1 ---
[INFO] Deleting D:\ProjectWork\demo\demo\module1\target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ module1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ module1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\ProjectWork\demo\demo\module1\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ module1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\ProjectWork\demo\demo\module1\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ module1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\ProjectWork\demo\demo\module1\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ module1 ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.demo.module1.Module1ApplicationTests
10:50:33.351 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
10:50:33.364 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframewor
k.test.context.CacheAwareContextLoaderDelegate)]
10:50:33.397 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.demo.module1.Module1ApplicationTests] from class [org.springframework.boot.test.context.SpringBoot
TestContextBootstrapper]
10:50:33.415 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.demo.module1.Module1ApplicationTests], using SpringBoot
ContextLoader
10:50:33.419 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.demo.module1.Module1ApplicationTests]: class path resource [com/demo/module1/Mod
ule1ApplicationTests-context.xml] does not exist
10:50:33.420 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.demo.module1.Module1ApplicationTests]: class path resource [com/demo/module1/Mod
ule1ApplicationTestsContext.groovy] does not exist
10:50:33.420 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.demo.module1.Module1ApplicationTests]: no resource found for suffixes {-contex
t.xml, Context.groovy}.
10:50:33.421 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.demo.module1.Module1ApplicationTests]: Module1ApplicationTests
does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
10:50:33.459 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.demo.module
1.Module1ApplicationTests]
10:50:33.520 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [D:\ProjectWork\demo\demo\module1\target\classes\com\demo\module1\Module1Appli
cation.class]
10:50:33.521 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.demo.module1.Module1Application for test class com.demo.module1.Module1ApplicationTests
10:50:33.600 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.demo.module1.Module1ApplicationTests]: using defaults.
10:50:33.601 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mocki
to.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfi
gure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriv
erTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.Dependency
InjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.Sql
ScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
10:50:33.610 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a
missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
10:50:33.610 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing de
pendency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
10:50:33.611 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@51c668e3, org.springframework.test.c
ontext.support.DirtiesContextBeforeModesTestExecutionListener@2e6a8155, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6221a451, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestE
xecutionListener@52719fb6, org.springframework.test.context.support.DirtiesContextTestExecutionListener@3012646b, org.springframework.test.context.event.EventPublishingTestExecutionListener@4a883b15, org.springframework.boot.test.mo
ck.mockito.ResetMocksTestExecutionListener@25641d39, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@7b36aa0c, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestE
xecutionListener@5824a83d, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@537f60bf, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@56773
23c]
10:50:33.614 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@6574a52c testClass = Module1ApplicationTests, testInstance = [null], tes
tMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@6c1a5b54 testClass = Module1ApplicationTests, locations = '{}', classes = '{class com.demo.module1.Module1Application}', contextIn
itializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframewor
k.boot.test.context.filter.ExcludeFilterContextCustomizer@39529185, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@31c88ec8, org.springframework.boot.test.mock.moc
kito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@3835c46, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot
.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@6c80d78a], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attribu
tes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
10:50:33.650 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrappe
r=true, server.port=-1}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-05-04 10:50:33.904 INFO 21276 --- [ main] c.demo.module1.Module1ApplicationTests : Starting Module1ApplicationTests on DESKTOP-MBI0KTI with PID 21276 (started by wei in D:\ProjectWork\demo\demo\module1)
2020-05-04 10:50:33.906 INFO 21276 --- [ main] c.demo.module1.Module1ApplicationTests : No active profile set, falling back to default profiles: default
2020-05-04 10:50:35.223 INFO 21276 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-04 10:50:35.483 INFO 21276 --- [ main] c.demo.module1.Module1ApplicationTests : Started Module1ApplicationTests in 1.821 seconds (JVM running for 2.638)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.415 s - in com.demo.module1.Module1ApplicationTests
2020-05-04 10:50:35.767 INFO 21276 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ module1 ---
[INFO] Building jar: D:\ProjectWork\demo\demo\module1\target\module1-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] ---------------------------< org.demo:demo >----------------------------
[INFO] Building demo 1.0-SNAPSHOT [2/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] module1 0.0.1-SNAPSHOT ............................. SUCCESS [ 5.770 s]
[INFO] demo 1.0-SNAPSHOT .................................. SUCCESS [ 0.078 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.076 s
[INFO] Finished at: 2020-05-04T10:50:36+08:00
[INFO] ------------------------------------------------------------------------
我们再创建第二个模块,用来测试同一个窗口下,多模块启动。步骤同module1,创建完成项目结构如下:
修改module2的application.properties文件,添加启动端口,以免冲突:
# spring
server.port=8081
分别启动:Module2Application.java、Module2Application.java,可以看到,两个都正常启动,这样在开发中,可以方便我们模块间的调试和整体结构的掌控。
调整子模块的父文件继承:
更改子模块pom文件的parent节点,修改为:
<parent>
<groupId>org.demo</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
在父文件pom中添加springBoot 资源依赖:
<!-- 管理依赖版本号,子项目不会默认依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
刷新maven依赖(一定要做,我很多时候就是这个不成功,才导致项目一直有问题):
再次启动:Module2Application.java、Module2Application.java,可以看到,两个都正常启动,如果启动测试类报错,先屏蔽掉测试类,后续需要测试类时再进行选择引用。
这样,以后公共引入可以直接在父文件进行引入并指定版本。
在父pom中,如果用<dependencyManagement>来管理引入,它是不会强制子模块集成的。如果需要全部子模块继承,那就直接使用<dependencies>即可,不用放入<dependencyManagement>中。
到此,项目结构我们搭建完毕,我们上传到码云上面。
gitee仓库搭建
登录码云,点击+号,选择新建仓库
创建完成:
代码提交到仓库:
在项目目录打开Git Bash:
执行git init
执行 git add . ,把代码添加到本地仓库(add 后面的空格+点 不能少)。
将项目提交到本地git仓库 (“first commit” 是备注信息 自己随便写)
git commit -m "重塑之路,项目框架搭建"
本地git仓库与远程仓库关联(https://gitee.com/backlife/tolerance.git 是远程仓库地址,从码云仓库复制而来。)
git remote add origin https://gitee.com/backlife/tolerance.git
执行推送,将项目推送到远程仓库(master是分支名 -f 强制推送)
$ git push -u origin master -f
如果报错:
remote: Repository Not Found
fatal: repository 'https://gitee.com/backlife/tolerance.git/' not found
请进入项目根目录,找到.git目录,进入.git找到config文件,修改config里面的远程地址url
之后再次执行强制提交即可。
由于我们是强制提交,所以覆盖了仓库自带的README文件,我们可以再次点击进行添加,此时也可以添加开源协议。
总结:
至此项目框架搭建完毕,后续练习内容将以模块的形式放入tolerance工程,并提交至码云。码云地址:https://gitee.com/backlife/tolerance.git 。
Nacos 源码构建我们已经说过两遍了,这里不在详细说明,请各位自行在tolerance构建Nacos Server 的子模块,这一块不在说明。
↓扫码关注不迷路,更多内容持续更新中↓
↓扫码关注,优惠先享↓