I'm writing a Spring Boot application with several @Configuration classes for rest APIs and for Kafka consumers/producers depending on which @Profile it chooses to initialize.
The first configuration class uses the REST interface, and I have these dependencies added. This starts up an embedded Tomcat instance and runs fine.
Here the problem is the other profiles should not spin a tomcat server, it should act only as a Kafka consumer.
Is there any way to stop spinning the @SpringBootApplication from starting up Tomcat based on profiles?
I created 2 configuration classes, one for Kafka and one for rest endpoints, and added @Profile annotation for each config class. Can someone guide me on how to stop spin tomcat from my app?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Main application:
@SpringBootApplication
@Import(value = {RestScanConfiguration.class, KafkaScanConfiguration.class})
public class MainApp {
public static void main(final String[] args) {
SpringApplication.run(MainApp.class, args);
}
}
RestScanConfiguration class:
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = "package.app.rest")
@Profile("!kafka")
public class RestScanConfiguration {
}
KafkaScanConfiguration class:
@Configuration
@EnableAutoConfiguration(
exclude = {
DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class
})
@ComponentScan(basePackages = {"package.app.kafka"})
@Profile("kafka")
public class KafkaScanConfiguration {
}
can someone guide me on this?
How to stop spinning the tomcat server in Kafka consumer/producer profile. Any help would be appreciated.