Admin client not registering to spring boot admin server - dashboard

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.

Related

H2 In-memory database not showing console in weblogic but shows in Tomcat

I am using H2 In-memory database for a spring-boot application with gradle.
I am able to see the console when i run in Tomcat but i am unable to see the h2-console when i deploy on weblogic. It works but i want to see the h2-console to do some CRUD operations.
Here is my application.properties for H2:
spring.datasource.h2.console.enabled=true
I can see the console at this endpoint for Tomcat:
http://localhost:8080/../../api/h2-console
But i cannot see the console at the below endpoint for weblogic:
http://localhost:7001/../../api/h2-console
Whitelabel Error Page
I am thinking that it could be a simple property file change. But my research could not find anything related. I would greatly appreciate any suggestion or help on this. Thank you
Try adding Spring Boot devtools maven dependency and repackaging your application.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

Spring boot devtools Livereload server not starting when spring-devtools.properties is configured

I am running a spring boot application on an embedded tomcat server on eclipse in my local environment with spring dev tools enabled. And I also have spring web flow configured in the application. Below are the version details.
Spring Boot 1.5.3.RELEASE
Spring Web Flow 2.4.4.RELEASE
The pom for dev-tools is configured as
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
My devtools configuration for livereload and restart in "application.properties" under resources is
spring.devtools.livereload.enabled=true
spring.devtools.restart.additional-exclude=/webapp/**,WEB-INF/view/**
spring.devtools.restart.enabled=true
With the above properties set, livereload and auto-restart work without any problems. But the spring-webflow related functionality doesn't work in the application.
Since its a known issue that spring-dev-tools and spring-web-flow don't play nice, I had to put this property as a workaround fix in "spring-devtools.properties" file under /resources/META-INF as shown below.
restart.include.spring=/spring-[\\s\\S]+\.jar
This property fixed the spring-web-flow problem but the livereload server doesn't start. The server console log as well doesn't show that it has started the livereload server on so and so port.
I am unable to pinpoint the what is causing this problem.
Can anyone help?
Update:
I can't seem to make this work. I think the workaround fix mentioned above is including the dev-tools classes as well in the Restart Classloader and hence preventing the livereload server from starting up.
Correct me If I am wrong.
Unable to start LiveReload server...
similar question here:
Unable to start LiveReload server
more info here: https://www.programmersought.com/article/11941784687/
We can only use one per IDE.
Go to the Spring application.properties and set all others to false:
spring.devtools.livereload.enabled=false

Serving log files from Spring Boot's embedded Tomcat

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.

Spring Boot: Do I have to add a jdbc pool dependency for Oracle connection?

First off I'm new to Spring Boot, so perhaps there is something simple I'm missing.
I have a small Spring Batch process that relies upon Spring Boot.
By default it uses the embedded H2 database.
I want it to use an oracle database.
So I set the url/username/password in the application.properties file
spring.datasource.url=jdbc:oracle:thin:#host:1521:batch
spring.datasource.username=username
spring.datasource.password=reallyCoolPassword
and add the dependecy to my Maven pom
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.client.version}</version>
</dependency>
I still get the embedded database. The only way I've been able to make it work is to add a dependency to a connection pool (for example tomcat).
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
Am I missing something? I was expecting Spring Boot to already have a dependency to tomcat that it would have brought in. Allowing me to override with dbcp or something else if needed.
hopefully someone can tell me what I've done wrong or help me straighten out my thinking.
In addition to providing url, name and password for DB you need to add spring.datasource.driverClassName.
We are using mysql as storage and we are adding this in properties:
spring.datasource.driverClassName: com.mysql.jdbc.Driver
Here is also link to properties for spring batch using oracle db.
Also you need to add your driver to project and oracle due to licence restrictions does not have public maven repository so you need to install driver. Here is useful link with walk through.

Deploying Simple Spring Hibernate Utility Project via Maven to Tomcat

My goal is understanding the J2EE lifecycle at a high-level with Spring, Hibernate, and Maven. From much research, I understand that Spring provides dependency injection and Hibernate provides object-relation mapping with databases. Maven is a tool to improve the build/deployment process from my understanding. With that said, everywhere I search I get more and more lost on configuration files (i.e. pom.xml, server.xml, etc.), terminology, and alternatives such as Gradle. I just want to build and launch the application and be able to see via http://localhost:8080 in tomcat.
At first, I couldn't get the default project (picture attached) built, but after further research found that I needed to Maven clean and Maven install.
I also modified settings in pom.xml changing version numbers and the database to use MySQL.
<properties>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
<spring.framework.version>3.1.1.RELEASE</spring.framework.version>
</properties>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.1.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
The next issue I had was in OrderPersistenceTests.java it used org.hibernate.classic.Session which is no longer the correct class path and found that it needed to be org.hibernate.Session.
Finally, I was able to get it to build but cannot figure out how to deploy to Tomcat from Spring Tool Suite.
I have put together a simple example using Maven, Spring, Hibernate, and ExtJS for the front end at the following link:
https://github.com/drembert/java-webapp-sample
If you are using Spring Source Tool Suite which it looks like you are in the screen shot, you should be able to import everything using the "Import Maven Projects" option. The example uses Hypersonic as the in-memory DB to allow easier deployment. Keep in mind this example generates two different .war files (one is presentation-layer and the other is service-layer) to emulate a simple RESTful service so both will need to be deployed to the Spring tcServer (STS's version of Tomcat), but once they are you should be able to view the GUI at http://localhost:8080/presentation-layer. Another thing to make note of is that this example currently doesn't have a security layer which would normally be implemented using Spring security, but I am working on adding that in the near future.

Resources