I'm building a slightly customised version of Kie Server using spring boot starter dependencies. When running with embedded Tomcat, there are no issues.
However, when a war file is built and deployed to a Tomcat server, I see the following behaviour.
First, as with embedded Tomcat, server starts fine and uses KieServerAutoConfiguration application.properties to configure data source, etc:
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerAutoConfiguration] [kieServer] --> KieServer (id kie-server (name kie-server)) started initialization process.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [<init>] --> Starting server in 'DEVELOPMENT' mode..
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Selected startup strategy SkipPreviousStateLoadingStartupStrategy - ignores any containers from previous state.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Configured 'KieServerStateFileRepository' server state repository.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Server Default Extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Drools KIE Server extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [JSONMarshaller] [<clinit>] --> Marshaller extensions init.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> jBPM KIE Server extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [PolicyManager] [lambda$start$0] --> Registered KeepLatestContainerOnlyPolicy{interval=0 ms} policy under name KeepLatestOnly.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [PolicyManager] [start] --> Policy manager started successfully, activated policies are [].
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [markAsReady] --> KieServer kie-server is ready to receive requests.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [**KieServerAutoConfiguration**] [kieServer] --> KieServer (id kie-server) started successfully.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [ServerImpl] [initDestination] --> Setting the server's publish address to be /.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServer] [logStarted] --> Started KieServer in 17.509 seconds (JVM running for 29.18).
At this point, org.kie.server.remote.rest.common.Bootstrap implements ServletContextListener which is annotated with @WebListener gets called.
The line KieServerLocator.getInstance(); then creates a new instance of KieServerImpl which starts the server load sequence once more, however this time the properties from the application.properties file are not available to the context, it instead has access to properties from the kie server state xml file and jvm parameters.
Hence there are exceptions during this duplicate startup sequence - Bootstrap class can't find h2 datasource, can't load all the extensions - shortened version below:
[INFO] [RMI TCP Connection(2)-127.0.0.1] [Bootstrap] [contextInitialized] --> KieServer (id kie-server (name kie-server)) started initialization process.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [<init>] --> Starting server in 'DEVELOPMENT' mode..
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Selected startup strategy SkipPreviousStateLoadingStartupStrategy - ignores any containers from previous state.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Configured 'KieServerStateFileRepository' server state repository.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Server Default Extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [LogHelper] [logPersistenceUnitInformation] --> HHH000204: Processing PersistenceUnitInfo [name: org.jbpm.domain].
[ERROR] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Error when initializing server extension of type jBPM KIE Server extension.
java.lang.RuntimeException: Unable to create EntityManagerFactory due to Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
...
Caused by: org.hibernate.engine.jndi.JndiException: Unable to lookup JNDI name [java:jboss/datasources/ExampleDS]
...
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Drools KIE Server extension has been successfully registered as server extension.
[WARN] [RMI TCP Connection(2)-127.0.0.1] [CaseKieServerExtension] [init] --> jBPM extension not found, Case Management cannot work without jBPM extension, disabling itself.
... loads all extensions ignoring the disabled settings in application.properties ...
[WARN] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> Case-Mgmt KIE Server extension has not been registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [OptaplannerKieServerExtension] [init] --> Creating a ThreadPoolExecutor with corePoolSize = 8, maximumPoolSize = 8, queueSize = 8.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> OptaPlanner KIE Server extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [init] --> DMN KIE Server extension has been successfully registered as server extension.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [PolicyManager] [lambda$start$0] --> Registered KeepLatestContainerOnlyPolicy{interval=0 ms} policy under name KeepLatestOnly.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [PolicyManager] [start] --> Policy manager started successfully, activated policies are [].
[INFO] [RMI TCP Connection(2)-127.0.0.1] [KieServerImpl] [markAsReady] --> KieServer kie-server is ready to receive requests.
[INFO] [RMI TCP Connection(2)-127.0.0.1] [**Bootstrap**] [contextInitialized] --> KieServer (id kie-server) started successfully.
Artifact kie-server:war: Artifact is deployed successfully
My question is, what is the proper approach to fix these errors? The kie server still seems to work fine, as it is able to access the data source specified in application.properties and using auto configuration. However it is annoying to see these stack traces and duplicate context load related to Bootstrap.
Shortened pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
</parent>
...
<properties>
...
<kie.version>7.74.1.Final</kie.version>
...
</properties>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-server-spring-boot-starter</artifactId>
<version>${kie.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kie.server</groupId>
<artifactId>kie-server-client</artifactId>
<version>${kie.version}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
...
Entry point:
package com.***.kie;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.kie.server.api.KieServerConstants;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@EnableEncryptableProperties
@SpringBootApplication
public class KieServer extends SpringBootServletInitializer {
public static void main(String[] args) {
/* Setting a custom strategy so that KIE does not load containers from previous session - Spring Boot entry point */
System.setProperty(KieServerConstants.KIE_SERVER_STARTUP_STRATEGY, "SkipPreviousStateLoadingStartupStrategy");
SpringApplication.run(KieServer.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
/* Setting a custom strategy so that KIE does not load containers from previous session - Tomcat entry point */
System.setProperty(KieServerConstants.KIE_SERVER_STARTUP_STRATEGY, "SkipPreviousStateLoadingStartupStrategy");
return application.sources(KieServer.class);
}
}