Spring actuator in 2.7 not available get 404 - spring-boot

i am trying to get actuator refresh to work and i cant seem to get it to work. I keep getting 404. The application is basic hello world, have not added anything other than a controller which responds with "Hello". That all works.. but i cant seem to get access to the health or info endpoints.. i read these should be available
my versions are:
Gradle:
plugins {
id 'org.springframework.boot' version '2.7.3'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
ext {
set('springCloudVersion', "2021.0.3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-config'
implementation 'org.projectlombok:lombok:1.18.22'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.3'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
tasks.named('test') {
useJUnitPlatform()
}
Tried:
Application.properties
server:
port: 9999
server:
port: 9999
management:
health:
refresh:
enabled: true
This too:
management:
info:
env:
enabled: true
i dont think the last one is even available in 2.7
Im using the latest actuator which is 2.7.3, and the url im trying is
http://localhost:9999/actuator/health

I'm upgrading our application's spring boot version from 2.6 to 2.7. I had a similar problem, the actuator endpoint did not show up when I changed spring-boot-starter-actuator version from 2.6.11 to any 2.7.* version.
But when I added spring-boot-actuator-autoconfigure dependency manually, the actuator started to work as before.
So try to add org.springframework.boot:spring-boot-actuator-autoconfigure to your to dependencies.
I cant figure out why this solves the problem. It should work without adding this dependency manually. Maybe the changes in the spring autoconfiguration somehow affected the actuator auto configuration.

Related

How can I use Spring Cloud OpenFeign with Spring Boot 3.0.0-M4?

I want to use Spring Cloud OpenFeign with Spring Boot 3.0.0-M4 But I could not find the compatible version of Spring Cloud OpenFeign with spring boot 3.0.0-M4.
for using OpenFeign with this version of spring boot what should I do?
The new Spring Boot milestone version 3.0.0-M5 got released end of September.
You can use the corresponding Spring Cloud version 2022.0.0-M5 which includes Spring Cloud Openfeign 4.0.0-M5.
See https://spring.io/blog/2022/10/06/spring-cloud-2022-0-0-m5-is-now-available
(The same most probably works with M4 if you really have to use it)
However I would advise on using https://start.spring.io to generate your project stub and maven or gradle files that take care of selecting the correct versions for Spring Cloud modules like Openfeign.
Shortened example for build.gradle:
plugins {
id 'org.springframework.boot' version '3.0.0-M5'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
id 'java'
}
sourceCompatibility = '17'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', "2022.0.0-M5")
}
dependencies {
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}

Unable to connect to h2 database

I have been trying to integrate h2 DB with spring boot application and I am getting the following error when trying to connect from the h2-console
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help)
org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200]
I tried adding the following properties to the application.properties file:
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create
It still does not seem to work.
This is how my build.gradle file looks like
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-jpa'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
It works as expected if you replace the line
implementation 'org.springframework.data:spring-data-jpa'
with
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
in build.gradle if you make sure that the field JDBC URL in the login mask has the value jdbc:h2:mem:testdb.
You get the correct build.gradle if you use the Spring Initializr and add
Lombok
Spring Data JPA
H2 Database
Spring Web
If you want to add dependencies to a project that was originally created with the Spring Initializr, it's usually a good idea to go back to https://start.spring.io/, add all dependencies, hit the Explore button, and copy & paste the generated build.gradle into the existing project.

How to use spring boot in gradle without the spring boot gradle plugin

Can anyone show me or point me to a spring boot gradle project that does not make use of the spring boot gradle plugin.
I'm looking for something like a spring boot starter web hello world example that doesn't use the gradle plugin.
I can't imagine that the plugin is a requirement, but a search for examples all seem to lean on the gradle plugin, which lets just say is not an option in my environment, and no I can't switch to maven either.
Ideally the gradle build would work by adding something like the following:
gradle.properties
springBootVersion=2.1.3.RELEASE
build.gradle
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
}
I used the spring dependency management plugin, and it works
buildscript {
ext {
springDepManagementVersion = '1.0.10.RELEASE'
springBootVersion = '2.6.6'
springCloudVersion = "2021.0.1"
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:${springDepManagementVersion}"
}
}
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-mail'
implementation 'org.springframework.boot:spring-boot-starter-security'
...
}
I can't use spring boot gradle plugin, since I can only use gradle 6.7.1, while spring boot gradle plugin requires gradle version at least 6.8 to support spring boot 2.6. I was inspired by the spring cloud bom solution.

Spring Data Neo4j OGM Gradle Dependency Issues

I am trying to manage my spring dependencies using gradle and the spring dependency management plugin. Currently this brings down version 5.0.3.RELEASE of spring-data-neo4j which according to the pom here, should bring down version 3.0.3 of the neo4j-ogm, but instead it brings down version 2.1.5. This means that even though I've followed the docs to the letter about configuration that the ConfigurationBuilder symbol is not found. Any help would be greatly appreciated. I am currently using gradle 4.4.1
buildscript {
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/plugins-snapshot' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE")
classpath 'io.spring.gradle:dependency-management-plugin:1.0.5.BUILD-SNAPSHOT'
}
}
plugins {
id "io.spring.dependency-management" version "1.0.4.RELEASE"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
ext {
springVersion = '5.0.3.RELEASE'
springDataVersion = 'Kay-SR3'
}
dependencyManagement {
imports {
mavenBom "org.springframework:spring-framework-bom:${springVersion}"
mavenBom "org.springframework.data:spring-data-releasetrain:${springDataVersion}"
}
}
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-release'
}
}
dependencies {
compile group: "org.springframework.boot", name: "spring-boot-starter-web"
compile group: "org.springframework.boot", name: "spring-boot-starter-security"
compile group: "org.springframework", name: "spring-aspects"
compile group: "org.springframework.data", name: "spring-data-neo4j"
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
testCompile group: "org.springframework.boot", name: "spring-boot-starter-test"
testCompile group: "org.neo4j", name: "neo4j-ogm-embedded-driver", version: "3.1.0"
}
You are using the spring-boot-gradle-plugin with version 1.5.8.RELEASE. This will pull in the version 4 of SDN and its dependency OGM 2.1.x when you declare the dependency here compile group: "org.springframework.data", name: "spring-data-neo4j".
The only solution at this point is to use Spring Boot 2 RC1. If you would include SDN with its dependencies to Spring Data commons and Spring Framework 5 you will mess up your class path because Spring Boot 1 is based on Spring Framework 4.
Background: Tried it once to integrate SDN 5.x in Spring Boot 1 but it did not work out, you will lose all benefits of Spring Boot since you have to deactivate pretty everything.

Why does Neo4j OGM with Spring Boot 2.0.0.M4 apparently require the embedded driver?

I have been trialling Spring Boot 2 (2.0.0.M4 at this stage) with the latest Spring Data Neo4j (currently 5.0.0.RC3) and can't seem to get it running.
I get the following error:
org.neo4j.ogm.exception.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
I don't ask for an embedded driver, nor do I want one. I only want to use the bolt driver, which is already a dependency of spring-data-neo4j.
I've published a project to Github that was built using output from Spring Initializr that can be run to expose the error.
For reference, my build.gradle is as follows. Am I mis-configuring my project? Or is there something more serious wrong with the current Spring and Neo4j milestone builds?
buildscript {
ext {
springBootVersion = '2.0.0.M4'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/snapshot' }
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
version = "0.0.1-SNAPSHOT"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile "org.apache.tomcat.embed:tomcat-embed-jasper"
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-data-neo4j"
runtime "org.springframework.boot:spring-boot-devtools"
}
The rest of the code is available in Github as I mentioned earlier.
You don't have the embedded driver dependency anywhere, see
./gradlew dependencies
output and search for neo4j-ogm.*driver - only neo4j-ogm-bolt driver is present. So if you want to use bolt only you have the dependencies set up correctly.
The reason why you see this exception is because you configuration is wrong:
return new SessionFactory("com.example.domain");
This doesn't provide path to configuration file, the default then is impermanent embedded database, which needs the embedded driver - hence the exception.
You have two options
pass OGM configuration to SessionFactory:
#Bean
public org.neo4j.ogm.config.Configuration configuration() {
return new org.neo4j.ogm.config.Configuration.Builder(new ClasspathConfigurationSource("ogm.properties")).build();
}
#Bean
public SessionFactory sessionFactory() {
return new SessionFactory(configuration(), "com.example.domain");
}
beware that this is OGM only solution and doesn't support yml files.
use spring boot auto configuration for SDN - just delete the Neo4jConfiguration class, Spring Boot will detect there is no SessionFactory bean and will configure all required (including transaction manager). Keep your Application class and application.yml as it is.

Resources