Serving log files from Spring Boot's embedded Tomcat - spring-boot

I'm looking to have my log files available to an admin without needing to ssh to the host.
Hopefully something easy as http://myhost:myport/logs/app.log .
Is there any way to expose an endpoint using Spring Boot that would serve my log files?

Spring Boot Actuator
Add the following dependency to your application:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
And out of the box you'll get a lot of useful endpoints including: /logfile
No additional configuration necessary.

Related

Admin client not registering to spring boot admin server

I have created personal microservice and registered it to spring boot admin. Its working fine. But when I applied same dependency and properties in my organisation project then admin clients are not registering to spring boot admin server.
Even though both have same properties and dependencies, why my microservice is not registering
I tried creating spring boot admin server and trying to register admin clients on this server.
I am currently working on a small project where I'm connecting MSs to a spring boot admin server. Had some problems (my clients would not connect to the server) and that's how I ended up here.
From what you provided, it is very difficult to pinpoint the exact problem, so there will be a lot of guessing on my part. I can only share my experience in hope it can help you too. In the end, the problem for me was the configuration parameter
spring.boot.admin.client.url=...
which was misspelled... And since this will not raise any error messages, it took some time to fix.
Go through following steps:
add client dependencies:
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>
guessing you are using actuator, make sure there is a dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
expose actuator endpoints (probably not all like in my example) in application.properties
management.endpoints.web.exposure.include=*
point your MS client to the admin server (use correct url!)
spring.boot.admin.client.url=http://localhost:9080
make sure your admin server has following dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
make sure your admin server has the following annotation in the main class
#EnableAdminServer
make sure both server and client(s) are running correctly and can bind defined ports (change the default port if they run on the same machine - in the application.properties)
server.port=...
If there is no additional security level, these steps should be enough to connect client to the server. With security I have no experience, but the online documentation did seem straight forward.
In the end, you can always try to build a new MS with nothing except actuator and client, and try to connect it to the server. If nothing else, it will maybe provide insight which side is broken.
Without more details it is very difficult to provide more help.
Oh yeah, I do remember one more detail: I was mixing up versions of the spring boot and JDK and since JDK17 (and spring boot version >= 3.x) moved from javax to jakarta, had some problems with running the MS. But those errors were easy to fix from log info.

Spring boot without web but with actuator

Is it possible to run Spring Boot Application without web part but with actuator?
For instance I'd like to process some background operations.
My Application properties
management.server.port=8081
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s
Dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
When I run the app it stops and not running in background. Did not found the answer in the documentation.
No it is not possible or at least it will run without any errors but stop right after it get startet. Spring Boot starter web actually run an embedded server (Tomcat, Jetty, Netty ...) wich keep the process up.

Spring: spring-data-mongodb or spring-boot-starter-data-mongodb

Which's the difference between
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
</dependency>
and,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
I'm developing an spring boot service.
spring-boot-starter-data-mongodb contains configuration classes for Spring Boot. It also includes the spring-data-mongodb library so you would only need to include the start in your boot app:
https://search.maven.org/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/2.0.5.RELEASE/jar
spring-boot-starter-data-mongodb is a spring boot starter pom. For more information on starters:
spring-boot-starters
Dependency management is a critical aspects of any complex project. And doing this manually is less than ideal; the more time you spent on it the less time you have on the other important aspects of the project.
Spring Boot starters were built to address exactly this problem. Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors.

spring actuator for standalone spring boot application

we have standalone spring boot application which triggers some quartz jobs based on triggers. it is standalone jar file , no application server involved.
i am planning to add Spring actuator to it. is it possible to add actuator to spring boot application which is not running on any application server.
i did search in google and spring.io website but haven't found any relevant info. if i can add can someone help me how to do it or any link for documentation.
Thanks
Try adding the spring-boot-starter-web dependency to your pom.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I had the same issue and this resolved it for me.

Spring Boot Deployment Strategy

Am implementing the swagger 2 using Spring Boot. Using Dependencies-
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
It works good. But want to implement swagger in such a way that in production
swagger does not get deployed. Also will it be possible to host the swagger build differently than the application build on different host machines?
There are two approaches to do this.
Maven profile
By intrudue a maven profile like 'swagger' and add the springfox-swagger-ui related depdencenty to this maven profile. As maybe you need to use some swagger annotations in the java code, so it cannot eliminate the springfox-swagger2 dependency.
Spring profile( should be more better than option 1 )
For a standard spring-boot swagger2 config class, for example you can add the #Profile("swagger") annoation to enable the swagger2 integration only when add the spring.profiles.active=swagger in app running.
For the different host machines, I has no idea about that, but as my understanding, swagger will select all the spring boot endpoints so suppose you cannot leave them alone. But there is a library which can provides a way to publish springfox-swagger2 on spring boot actuator. so you can add management.port=8181 property in application.properties to makes spring-boot-actuator run on another TCP port.

Resources