Error: kie.container or kieModule bean – Null Pointer Exception? Solved!

I recently we faced an issue in my Drools Config class where we added config for kie container and kie modules.

It was working fine in normal windows server environment but we migrated our app into docker environment we faced below error.

When running our Java Spring Boot app (Fat Jar) on Docker Environment we are getting below error:

Error: Failed to instantiate [org.kie.api.builder.KieModule]: Factory method 'kieModule' threw an exception; nested exception is java.lang.NullPointerException

Method in our Drools Config class:

@Bean(KieModule)
public KieModule kieModule() {
   KieServices kservice = KieServices.Factory.get();
   final KieRepository kr = kservice.getRepository(); //failing here
   KieModule kieModule = new KieModule() {
        public ReleaseId getReleaseId(){ return releaseId.getDefaultReleaseId();}
};

kieRepository.addKieModule(kieModule);
return kieModule;

}
   
}

build.gradle has following dependencies

implementation 'org.kie:kie-spring:7.30.0:Final'
implementation 'org.drools:drools-core:7.30.0:Final'
implementation 'org.drools:drools-compiler:7.30.0:Final'

The functionality works fine in JVM and other servers but when deployed in internal Docker container it breaks at KieRepository instance and gives null pointer exception.

Solved by appending the kie.conf files using shadow plugin in gradle.

The problem is that when you compile your jar you are overriding the META-INF/kie.conf file.

Add following in your build.gradle:

dependencies{classpath("com.github.jengelman.gradle.plugins:shadow:4.0.4")}

apply plugin: 'com.github.johnengleman.shadow'

shadowJar{
 manifest{
    attribute('Main-Class': 'com.demo.HelloWorldApp')
}
append('META-INF/kie.conf')
}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s