I developed an application using SpringBoot on Eclipse(not STS-Eclipse). The project structure looks as below:
While the application running absolutely fine in Eclipse but unable to run when making an excecutable jar (lets say MyApp.jar). It seems to me that the executable is unable to load the application.properties
file or it is unable to parse the required property field value. I ran the application using debug mode but unable to find any clue regarding missing of application.properties
file. All it contains is NumberFormatException
.
Log Error details:-
[ERROR] 2017-08-04 12:03:36.301 [main] SpringApplication - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBusiness': Unsatisfied dependency expressed through fiel
d 'myCommonProperty'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myCommonConfig' define
d in URL [jar:file:/app/Keygen/bin/MyApp.jar!/com/keygen/config/MyCommonConfig.class]: Bean instantiation via constructor failed; neste
d exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.keygen.config.MyCommonConfig$$EnhancerBySpringCGLI
B$$f47f0d]: Constructor threw exception; nested exception is java.lang.NumberFormatException: For input string: "${thread.core.pool.size}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor
.java:588) ~[MyApp.jar:?]
MyCommonConfig.java
@Configuration
public class MyCommonConfig {
.
.
.
@Autowired
public MyCommonConfig(@Value("${thread.core.pool.size}")String corePoolSize,@Value("${thread.max.pool.size}")String maxPoolSize,@Value("${sys.blacklisted.keywords}")String blackListedKeywords,@Value("${sys.sleep.time}")String sleepTime,@Value("${sys.keyword.size}")String keywordSize,@Value("${sys.queue.size}")String queueSize) {
this.corePoolSize=Integer.parseInt(corePoolSize);//Getting Number format exception as the value parsed is "${thread.core.pool.size}" which should be "500"
this.maxPoolSize=Integer.parseInt(maxPoolSize);
this.blackListedKeywords=blackListedKeywords;
this.sleepTime=Integer.parseInt(sleepTime);
this.keywordSize=Integer.parseInt(keywordSize);
this.queueSize=Long.parseLong(queueSize);
LOGGER.info("Loading MyCommonConfig complete");
}
.
.
.
}
Below is my SpringBoot application class
@SpringBootApplication
public class MyApp{
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(MyApp.class);
springApplication.addListeners(new ApplicationPidFileWriter());
springApplication.setRegisterShutdownHook(true);
ApplicationContext applicationContext = springApplication.run(args);
MyAppBusiness myAppBusiness = applicationContext.getBean(MyAppBusiness.class);
myAppBusiness.serve();
}
}
I am executing the script ./keygen.sh
which contains the following command:
java -jar MyApp.jar
The binary structure looks as below:
Thanks in advance.
Update
Please note I am not using any building tool or STS-Eclipse to make execuatble runnable jar.
Update 2
Adding jar file details