может не на 100% удовлетворить ваши требования.
У меня есть два предложения.
легкий.
java -jar stackoverflow-1.0-SNAPSHOT.jar --spring.profiles.active=prod
и установите другое значение "@Profile" на вашем контроллере.
@RestController
@Profile("prod")
public class URLOneController {
@PostMapping(value = "/url", consumes="application/json", produces="application/json")
public ResponseEntity<HttpStatus> insertClaim(@RequestBody String messageBody) {
return new ResponseEntity<>(HttpStatus.OK);
}
}
второе предложение, динамическая загрузка beanDefiniton.
@Configuration
@ConditionalOnProperty(name="external.controller.enable",havingValue = "true")
public class ExternalClassDefinitionProcessor implements
BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Class<?> aClass = null;
try {
aClass = contextClassLoader.loadClass("com.jin.learn.demo.UrlOneController");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder
.genericBeanDefinition(aClass);
beanDefinitionBuilder.addPropertyReference("personDao", "personDao");
BeanDefinition personManagerBeanDefinition = beanDefinitionBuilder
.getRawBeanDefinition();
registry.registerBeanDefinition("UrlOneController",
personManagerBeanDefinition);
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
}
}
упакуйте ваш контроллер в обычный jar (не используйте spring-boot-maven-plugin)
запустите ваше приложение, как эта командная строка
java -Dloader.path="lib/,config/,/home/jin/Desktop/abc/target/abc-1.0-SNAPSHOT.jar" -jar stackoverflow-1.0-SNAPSHOT.jar --external.controller.enable=true
дополнительный контроллер в abc-1.0-SNAPSHOT.jar и ваше основное приложение - stackoverflow-1.0-SNAPSHOT.jar
Советы:
stackoverflow-1.0-SNAPSHOT.jar должен упаковывать zip формат.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>