I am running an Ubunut Linux Server and I am trying to run my Spring Boot Application as a service.
I have created a file in /etc/systemd/system/example.service with the following content:
[Unit]
Description = Java Test Service
Wants=network-online.target
After=network-online.target
[Service]
User=beeadmin
ExecStart=/home/beeadmin/beebackend/target/backend-0.0.1-SNAPSHOT.jar
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
The application starts but when i check the status i receive the following error:
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1372) ~[spring-beans-6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1348) ~[spring-beans-6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:769) ~[spring-beans-6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:752) ~[spring-beans-6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:493) ~[spring-beans-
6.1.1.jar!/:6.1.1]
Jan 05 11:58:43 beeguide backend-0.0.1-SNAPSHOT.jar[73319]: ... 59 common frames omitted
Jan 05 11:58:43 beeguide systemd[1]: beeguide.service: Main process exited, code=exited, status=1/FAILURE
Jan 05 11:58:43 beeguide systemd[1]: beeguide.service: Failed with result 'exit-code'.
There seems to be a problem with some autowired dependecies. I can not figure out why it executes normally when i run it like this:
java -jar /home/user/app/target/app.jar
I was expecting the .jar file to execute like it did when i run the .jar file by itself.
The
ExecStartcommand in your service file should include the samejava -jarcommand as when you're starting the app locally. Something like this:The Spring Boot documentation has further guidance on how to do this.