Java: Spring boot Tomcat Access Logs are not created at Tomcat Start - java

I want to access tomcat logs of my service which is build in spring boot having embedded tomcat 8 in it.
I have written following code in bootstrap.yml of my service.
server:
port: 8320
context-path: /luggage-service
tomcat:
accesslog:
directory: "/var/log/tomcat"
enabled: true
pattern: "{\"Hostname\":\"%h\", \"Logical username from identd\":\"%l\", \"Remote user\":\"%u\", \"Date&Time\":\"%t\", \"HTTP Status code\":\"%s\", \"Bytes Sent\":\"%b\", \"Time taken to process the request\":\"%D\", \"Local IPAdderss\":\"%A\", \"Local port\":\"%p\", \"Time taken to Commit the Request\":\"%F\", \"Request Method:%m User SessionID\":\"%S\", \"Requested URL path\":\"%U\", \"Local ServerName\":\"%v\"}"
When i build and run my service, then a file "access_log.yyyy-mm-dd.log" is created and when i hit calls of my service,then no logs are created in log file.
Logs are created when i stop my tomcat.
What changes do i need to do in my code?

Could you try:
server.tomcat.accesslog.buffered=false

Related

Spring boot embedded tomcat threadpool configuration

Application is built using spring boot.My application uses application.yaml for external config .But when i am trying to add below config in application.yaml , application fails to start with error as tomcat is not valid.However similar equivalent config I have tried in another application with application.propeties it works there.
server:
port:8080
tomcat:
max-threads:500
accept-count:500
max-connections:10000
min-spare-threads:500
What is the springBoot version being used in the other application ?
FYI
server.tomcat.max-threads is deprecated since Springboot 2.3, now use server.tomcat.threads.max in your Spring application.properties.
https://docs.spring.io/spring-boot/docs/2.4.0/reference/html/appendix-application-properties.html#common-application-properties
For me this seems to work in application.yaml
server:
port: 8080
tomcat:
max-threads: 500
accept-count: 500
max-connections: 10000
min-spare-threads: 500
or this in application.properties
server.port = 8080
server.tomcat.max-threads = 500
server.tomcat.accept-count = 500
server.tomcat.max-connections = 10000
server.tomcat.min-spare-threads = 500
If it doesn't work, maybe there is an error in your dependencies?

Cannot load keystore from system environment

I have a simple spring boot application running on HTTPS with SSL enabled
application.properties
server.port=8443
server.ssl.key-store=${SERVER_KEYSTORE}
server.ssl.key-store-password=${SERVER_KEYSTORE_PASSWORD}
where SERVER_KEYSTORE and SERVER_KEYSTORE_PASSWORD are system env variables
I generate a jar using mvn clean package and then run the executable jar. But I get the following error
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 8444 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 8444, or configure this application to listen on another port.
I have confirmed that port 8443 is not in use by any application.
Now, when I rewrite application.properties as
server.port=8443
server.ssl.key-store=/etc/ssl.keystore
server.ssl.key-store-password=secret
The application runs fine on port 8443 with HTTPS. But I don't want to have the path and password part of my codebase.
I even tried specifying the complete path to the env file as
server.ssl.key-store=/etc/environment/${SERVER_KEYSTORE}
server.ssl.key-store-password=/etc/environment/${SERVER_KEYSTORE_PASSWORD}
It still gives the same error
Some help will be highly appreciated. Thanks
The following error clearly says that tomcat cannot stat on 8444 port. If you want to verify, open command prompt and type the command netstat -a. This will give you which are the ports already occupied. You can run in different ports like 8090, 8091 etc. Besides, if you want to know more details, start spring boot in debug mode using your ide.
The Tomcat connector configured to listen on port 8444 failed to
start. The port may already be in use or the connector may be
misconfigured.
So I guess your question is how to read env properties in Spring application.properties.
Try this : https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/maven-plugin/examples/run-env-variables.html

Stackify Prefix for Java

I am trying out Stackify Prefix v3.0.18 to profile a Spring Boot application in WebLogic 12c. The JVM is started with the stackify-java-apm agent as per the instructions:
-javaagent:"C:\Program Files (x86)\StackifyPrefix\java\lib\stackify-java-apm.jar"
On accessing the Spring Boot Actuator's /health endpoint, I do not get anything reported in the Prefix dashboard at http://localhost:2012. Is anything amiss here?
A couple of observations were made; the Prefix agent was trying:
To load a properties file from a Linux/Unix path and failed to do so
16:16:24.826 [main] WARN com.stackify.apm.config.a - Unable to find properties file /usr/local/stackify/stackify-java-apm/stackify.properties
To write a file into a non-existent directory C:\Program Files (x86)\Stackify\stackify-java-apm\log\
I was unable to find an end-to-end demo or tutorial on setting up and using Prefix to profile a Java application.
I was looking on their support site and it seems that WebLogic 12c is not supported according to this link:
https://support.stackify.com/prefix-enable-java-profiling/
Have you tried submitting a ticket with them?
https://support.stackify.com/submit-a-ticket/

Spring Boot not obeying command line arguments

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/

Intellij 14 Glassfish Server is not connected. Deploy is not available

I'm trying to get my web app, which was developed and deployed successfully in Eclipse, to run on Intellij, but I failed. So I'm trying to get a basic app to run on Intellij with Glassfish first.
I'm following the steps in this tutorial https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+Java+EE+7+and+GlassFish+4.0. However, I can't deploy my app on to glassfish server. When I start the server from Intellij, this message appears:
C:\glassfish\bin\asadmin.bat start-domain domain1
[2015-06-25 10:45:58,857] Artifact Glassfish:war: Server is not connected. Deploy is not available.
Detected server admin port: 4848
Detected server http port: 9090
Waiting for DAS to start .........
Started domain: domain1
Domain location: C:\glassfish\glassfish\domains\domain1
Log file: C:\glassfish\glassfish\domains\domain1\logs\server.log
Admin port for the domain: 4848
Command start-domain executed successfully.
I'm using Java 6 with glassfish 3.0.1 (required by my company).
Glassfish server & deployed apps are running perfectly with eclipse.
I can't find any solution on the Internet. Please kindly help.
I had the same problem and I did the following:
Run my IDE as an administrator in Windows.
Credentials I entered in the glassfish configuration for domain1 were incorrect.
here
I change the user and the password by user: admin and password: admin .Entering the directory:
/glassfish4/glassfish/domains/domain1/config
Open the file admin-keyfile and replace what I was for:
admin;{SSHA256}t6QSpkyxWhpNFiV3RQ+LYgVczWIJVylE3f6akcXTRLJm9MKs983QAA==;asadmin
Open the file local-password and replace what I was for:
6588CB5CBF61A96DB036AC047837A1C4468EC2C4
And ready new user and new password!and Enter the credentials in intellij.
I hope it helps you!

Categories

Resources