嗨,我对春季启动很陌生。我有一个带有控制器、服务和dao(比如a(的spring-boot应用程序。有没有什么方法可以把这个应用程序用作依赖项,比如当我运行另一个以a为依赖项的spring-boot应用程序(比如B(时。我必须能够在A和B中运行控制器、Services和Dao。这可能吗?如果可能怎么做?
你当然可以做到!使用类似的exec
插件
例如,在服务Apom.xml
中提及此
<build>
...
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
张贴mvn clean install
,你会看到你的服务a的一个版本。拿起那个版本和
通过指定如下的依赖标签,将服务A用作服务B中的依赖项
<dependencies>
<dependency>
<groupId> com.yourAppGroup </groupId>
<artifactId> com.serviceA </artifactId>
<version> 1.0-Snapshot </version>
</dependency>
</dependencies>
我建议不要使用依赖关系中的控制器/服务,而只使用DAO。服务特定代码应仅在服务中!