How to wrap Spring Boot application as a linux daemon and to set it to read from application.properties.
To start the jar with the parameters from the application.properties I am using this command:
java -Dspring.config.location=/application.properties -jar MyJar.jar
Where to set this in wrapper.conf?
I have tried like this but the jar is not starting with the parameters from the application.properties.
wrapper.java.command=java
wrapper.java.command.loglevel=INFO
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperJarApp
wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=/opt/MyService/lib/MyApp.jar
wrapper.java.library.path.1=../lib
wrapper.logfile=../logs/wrapper.log
wrapper.app.parameter.1=/opt/MyService/lib/MyApp.jar
wrapper.app.parameter.2=-c
wrapper.app.parameter.3=/opt/MyService/lib/conf
Try with this:
wrapper.java.additional.1=-Dspring.config.location=/opt/MyService/lib/conf/application.properties
Related
I am starting spring boot project as follows
java -classpath "/home/madhur/github/fantasy_fury/target/fantasy_fury.jar:/home/madhur/github/fantasy_fury/target/dependency/*:/home/madhur/github/fantasy_fury/conf" com.games24x7.fantasy.fury.FantasyFuryInit
The conf folder has an application.properties with following contnents
zkHost=${ZK_CLUSTER_URLS}
Now, I am trying to read this variable as follows:
#Value("${zkHost:localhost}")
String zkHost;
However, it does not contain the actual value, but the default value localhost value every time.
Tried to set it as follows:
export ZK_CLUSTER_URLS=madhur1;java -classpath "/home/madhur/github/fantasy_fury/target/fantasy_fury.jar:/home/madhur/github/fantasy_fury/target/dependency/*:/home/madhur/github/fantasy_fury/conf" com.games24x7.fantasy.fury.FantasyFuryInit
Then also, the output is localhost. What I am missing?
Spring boot version is 1.4
How to check what values are consumed by a spring boot java application from the Linux command line or in the docker container?
I have a spring boot java application that has the below parameters for email
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=admin#qtech.com
spring.mail.password=${GPASSWORD}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.ssl.trust=smtp.gmail.com
I'm passing GPASSWORD as an environment variable to the docker/k8s container.
How can I check what value/values are being consumed by the java application, especially spring.mail.password field.
I tried the below commands
printenv
env
But they list all environment variables being passed to all containers like the below environment variable.
GPASSWORD=bond007
So Is there a way to check what values are being consumed by the spring boot java application inside a pod or container?
You can use Slf4j annotation and log like below:
#Value("${spring.mail.host}")
private String mailHost;
log.info("spring.mail.host: "+mailHost);
I am working on Spring boot application. I run my application via a batch file using:
java -jar -Dspring.config.additional-location=file:/config/ -Dspring.profiles.active=profile myApplication.jar
pause
This is working fine. However, I want to delete Ojdbc6 jar entry from my Pom file and define it to my classpath via a batch file, like so:
SET CLASSPATH=%CLASSPATH%ojdbc6.jar;
echo %CLASSPATH%
java -jar -Dspring.config.additional-location=file:/config/ -Dspring.profiles.active=profile myApplication.jar --classpath=%CLASSPATH%
pause
This is not working and I'm getting an error:
Unable to create initial connections of pool.
java.sql.SQLException: Unable to load class: oracle.jdbc.OracleDriver from ClassLoader:org.springframework.boot.loader.LaunchedURLClassLoader#439f5b3d;ClassLoader:TomcatEmbeddedWebappClassLoader
context: application name
delegate: true
----------> Parent Classloader:
org.springframework.boot.loader.LaunchedURLClassLoader#439f5b3d
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:292)**
Use -classpath=%CLASSPATH% instead of --classpath=%CLASSPATH%
Ref. link: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html
I'm creating a custom Dockerfile with extensions for official keycloak docker image. I want to change web-context and add some custom providers.
Here's my Dockerfile:
FROM jboss/keycloak:7.0.0
COPY startup-config.cli /opt/jboss/tools/cli/startup-config.cli
RUN /opt/jboss/keycloak/bin/jboss-cli.sh --connect --controller=localhost:9990 --file="/opt/jboss/tools/cli/startup-config.cli"
ENV KEYCLOAK_USER=admin
ENV KEYCLOAK_PASSWORD=admin
and startup-config.cli file:
/subsystem=keycloak-server/:write-attribute(name=web-context,value="keycloak/auth")
/subsystem=keycloak-server/:add(name=providers,value="module:module:x.y.z.some-custom-provider")
Bu unfortunately I receive such error:
The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: WFLYPRT0053: Could not connect to remote+http://localhost:9990. The connection failed: Connection refused
The command '/bin/sh -c /opt/jboss/keycloak/bin/jboss-cli.sh --connect --controller=localhost:9990 --file="/opt/jboss/tools/cli/startup-config.cli"' returned a non-zero code: 1
Is it a matter of invalid localhost? How should I refer to the management API?
Edit: I also tried with ENTRYPOINT instead of RUN, but the same error occurred during container initialization.
You are trying to have Wildfly load your custom config file at build-time here. The trouble is, that the Wildfly server is not running while the Dockerfile is building.
Wildfly actually already has you covered regarding automatically loading custom config, there is built in support for what you want to do. You simply need to put your config file in a "magic location" inside the image.
You need to drop your config file here:
/opt/jboss/startup-scripts/
So that your Dockerfile looks like this:
FROM jboss/keycloak:7.0.0
COPY startup-config.cli /opt/jboss/startup-scripts/startup-config.cli
ENV KEYCLOAK_USER=admin
ENV KEYCLOAK_PASSWORD=admin
Excerpt from the keycloak documentation:
Adding custom script using Dockerfile
A custom script can be added by
creating your own Dockerfile:
FROM keycloak
COPY custom-scripts/ /opt/jboss/startup-scripts/
Now you can simply start the image, and the built features in keycloak (Wildfly feature really) will go look for a config in that spedific directory, and then attempt to load it up.
Edit from comment with final solution:
While the original answer solved the issue with being able to pass configuration to the server at all, an issue remained with the content of the script. The following error was received when starting the container:
=========================================================================
Executing cli script: /opt/jboss/startup-scripts/startup-config.cli
No connection to the controller.
=========================================================================
The issue turned out to be in the startup-config.cli script, where the jboss command embed-server was missing, needed to initiate a connection to the jboss instance. Also missing was the closing stop-embedded-server command. More about configuring jboss in this manner in the docs here: CHAPTER 8. EMBEDDING A SERVER FOR OFFLINE CONFIGURATION
The final script:
embed-server --std-out=echo
/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheThemes,value=false)
/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheTemplates,value=false)
stop-embedded-server
WildFly management interfaces are not available when building the Docker image. Your only option is to start the CLI in embedded mode as discussed here Running CLI commands in WildFly Dockerfile.
A more advanced approach consists in using the S2I installation scripts to trigger CLI commands.
Put together a very basic Spring Boot RESTful backend with some CRUD endpoints. Trying to start it up on my Centos7 server. However I already have an application listening on its default port, 8080, so I have to configure that.
I have tried:
java -jar target/rest-1.0-SNAPSHOT.jar --server.port=8090
java -jar target/rest-1.0-SNAPSHOT.jar --Dserver.port=8090
java -jar target/rest-1.0-SNAPSHOT.jar --port=8090
java -jar target/rest-1.0-SNAPSHOT.jar --Dport=8090
My application.properties contains the line:
server.port=${port:8090}
Spring Boot still starts up the embedded Tomcat container on port 8080. It's not getting the message. What am I missing?
Edit: setting SERVER_PORT=8090 was effective - see below
Try with -Dserver.port=8090 note single -
or
server.port=xxxx in application.properties file
EDIT:-
Check your log, below line will echo in console 2015-10-16 23:13:23.082 INFO 4228 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8090 (http)
VM arg overrides application.properties
If you have a "application.yml" or "application.properties" in the same folder of jar, the jar will take preference of the external configuration file.
Doesnt make sense for me, but its true. The springboot has higher priority to external configuration file instead the internal one.
We have four different ways to change default port.
Using application.properties or application.yml
Implementing EmbeddedServletContainerCustomizer interface
Using SpringApplication class
Change port directly through command line
For more details, visit below
http://www.javainterviewpoint.com/spring-boot-change-embedded-tomcat-default-port/