Reputation: 1231
Just trying out micronaut with Spring capability, and can't get access to my /actuator endpoints Spring Boot v2.3.0 release and micronaut 2.0.0.M3
I created a basic micronaut project using the mn create-app xxx --lang groovy
.
I have then added the spring dependencies and micronaut-spring and associated annotation processors.
My build.gradle now looks as follows
plugins {
id "groovy"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "application"
id "net.ltgt.apt" version "0.21" //enables annotation preproccessing support
id "net.ltgt.apt-idea" version "0.21"
id "org.springframework.boot" version "2.3.0.RELEASE"
id "io.spring.dependency-management" version "1.0.9.RELEASE"
}
ext['groovy.version'] = '3.0.4'
version "0.1"
group "com.softwood"
repositories {
mavenCentral()
maven { url "https://jcenter.bintray.com" }
}
configurations {
// for dependencies that are needed for development only
developmentOnly
}
dependencies {
//annotation processors
annotationProcessor platform("io.micronaut:micronaut-bom:$micronautVersion")
annotationProcessor "io.micronaut.spring:micronaut-spring-boot-annotation"
annotationProcessor "io.micronaut.spring:micronaut-spring-web-annotation"
testAnnotationProcessor "io.micronaut.spring:micronaut-spring-web-annotation:2.0.1"
//latest groovy v3
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.4' //, ext: 'pom'
//spring
compileOnly "io.micronaut.spring:micronaut-spring-annotation:2.0.1"
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation group: 'io.micronaut.spring', name: 'micronaut-spring-web', version: '2.0.1'
runtime ("io.micronaut.spring:micronaut-spring-boot:2.0.1")
compileOnly platform("io.micronaut:micronaut-bom:$micronautVersion")
compileOnly "io.micronaut:micronaut-inject-groovy"
implementation platform("io.micronaut:micronaut-bom:$micronautVersion")
implementation "io.micronaut:micronaut-runtime-groovy"
implementation "io.micronaut:micronaut-validation"
implementation "javax.annotation:javax.annotation-api"
implementation "io.micronaut:micronaut-http-server-netty"
implementation "io.micronaut:micronaut-http-client"
runtimeOnly "ch.qos.logback:logback-classic:1.2.3"
testCompileOnly platform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation platform("io.micronaut:micronaut-bom:$micronautVersion")
testImplementation("org.spockframework:spock-core:2.0-M2-groovy-3.0") {
exclude group: "org.codehaus.groovy", module: "groovy-all"
}
testImplementation "io.micronaut:micronaut-inject-groovy"
testImplementation "io.micronaut.test:micronaut-test-spock"
testImplementation "io.micronaut.test:micronaut-test-junit5"
}
test.classpath += configurations.developmentOnly
mainClassName = "com.softwood.Application"
//added - enable incremetal compile feature - can't enable with annotation processors !
/*tasks.withType(GroovyCompile).configureEach {
options.incremental = true
}*/
tasks.withType(GroovyCompile) {
groovyOptions.forkOptions.jvmArgs.add('-Dgroovy.parameters=true')
}
shadowJar {
mergeServiceFiles()
}
tasks.withType(JavaExec) {
classpath += configurations.developmentOnly
jvmArgs('-noverify', '-XX:TieredStopAtLevel=1', '-Dcom.sun.management.jmxremote')
}
I have adjusted a HelloController as follows
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.HttpStatus
import org.springframework.boot.actuate.endpoint.annotation.Endpoint
@Controller("/hello")
@Endpoint
class HelloController {
@Get("/")
String index() {
return 'hello william'
}
}
and marked the Application class as being a SpringbootApplication - but call the Micronaut.run() to build the MN context etc
import io.micronaut.runtime.Micronaut
import groovy.transform.CompileStatic
import org.springframework.boot.autoconfigure.SpringBootApplication
@CompileStatic
@SpringBootApplication
class Application {
static void main(String[] args) {
Micronaut.run(Application)
}
}
I tried to adjust application.yml to expose all the endpoints as follows
micronaut:
application:
name: micronaut-std-app
management:
endpoints:
web:
exposure:
include=*:
This all compiles ok, and runs ok. if you invoke the localhost:8080/hello
you get the expected string
if you try and access the actuator endpoints - nothing is being generated, and the browser displays
{"message":"Page Not Found","_links":{"self":{"href":"/actuator/health","templated":false}}}
if your trying to do a mixed micronaut and spring project, then how do you get any actuator endpoints enabled for your MN pre processed controllers etc ?
Upvotes: 1
Views: 1360
Reputation: 159
If you just want a health check endpoint, Micronaut have build in health check endpoint available.
Add in the build.gradle the fallowing dependence to add the endpoints like health:
implementation("io.micronaut:micronaut-management")
You can add in the application.yml
endpoints:
health:
enabled: true
Then change the health check url to "/health"
Upvotes: 4