我的MainProject中有三个子项目,而其中一个子项目作为提供服务的公共项目。如何基于spring boot创建这个项目结构?
MainProject
|
|__subprojects
| |
| |__projectA (run as spring boot project)
| | |
| | |_pom.xml
| |
| |__common (provide services to A & B)
| | |
| | |_pom.xml
| |
| |__projectB (run as spring boot project)
| |
| |_pom.xml
|
|__pom.xml
这就是我的方式: 首先,我将我的共同项目作为一个春季启动项目。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
我使用@ComponentScan,@ MapperScan来获取组件和精通,这个子项目可以作为SpringBootApplication使用。
然后,当我运行projectA时,出了点问题。这是projectA中的pom.xml:
<dependency>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>my-common</artifactId>
<version>1.0.SNAPSHOT</version>
</dependency>
projectA以同样的方式运行:
@Configuration
@ComponentScan(basePackages = {"com.aaa.common.service",
"com.common.mapper",
"com.projectA.controller",})
@MapperScan(basePackages = {"com.common.mapper",})
@SpringBootApplication
public class ProejctAConf {
public static void main(String[] args) {
SpringApplication.run(ProejctAConf, args);
}
}
但程序错误:
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@60015ef5: startup date [Wed Sep 13 16:15:06 CST 2017]; root of context hierarchy
有没有一个很好的解决方案来运行projectA作为Spring启动应用程序?或者我只是以错误的方式运行projectA?或者我的项目结构不对?
TIA