Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions parent-spring-6/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Parent Spring 5

This is a parent module for all projects using Spring 5
Comment on lines +1 to +3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring 6

41 changes: 41 additions & 0 deletions parent-spring-6/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>parent-spring-6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>parent-spring-6</name>
<packaging>pom</packaging>
<description>Parent for all spring 6 core modules</description>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
</dependencies>

<properties>
<spring.version>6.0.8</spring.version>
</properties>

</project>
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>checker-framework</module>
Expand Down Expand Up @@ -409,6 +410,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>spring-4</module>
Expand Down Expand Up @@ -469,6 +471,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>apache-spark</module>
Expand Down Expand Up @@ -511,6 +514,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>checker-framework</module>
Expand Down Expand Up @@ -579,6 +583,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>spring-4</module>
Expand Down Expand Up @@ -631,6 +636,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>

<module>apache-spark</module>
Expand Down Expand Up @@ -895,6 +901,7 @@
<module>spring-5-webflux</module>
<module>spring-5-webflux-2</module>
<module>spring-activiti</module>
<module>spring-actuator</module>
<module>spring-core-2</module>
<module>spring-core-3</module>
<module>spring-credhub</module>
Expand Down Expand Up @@ -1196,6 +1203,7 @@
<module>parent-boot-2</module>
<module>parent-spring-4</module>
<module>parent-spring-5</module>
<module>parent-spring-6</module>
<module>parent-java</module>
</modules>

Expand Down
75 changes: 75 additions & 0 deletions spring-actuator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-actuator</artifactId>
<name>spring-actuator</name>
<packaging>war</packaging>
<description>Demo project for Spring Boot Actuator without Spring Boot</description>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-spring-6</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring-6</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- Jetty embedded -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
<!-- to run the server, use mvn jetty:run -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<properties>
<spring-boot.version>3.0.6</spring-boot.version>
<jetty.version>11.0.15</jetty.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.baeldung.spring.actuator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ActuatorConfiguration {

@Bean
public HealthIndicator sampleHealthIndicator() {
return Health.up()
.withDetail("info", "Sample Health")
::build;
}

@Bean
public InfoContributor provideSampleInfos() {
return builder ->
builder
.withDetail("app-title", "Actuator Sample Application");

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.baeldung.spring.actuator;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;

@EnableAutoConfiguration
@PropertySource("classpath:application.properties")
@ComponentScan(basePackageClasses = AppConfig.class)
public class AppConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.baeldung.spring.actuator;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class Start {

private static final Logger logger = LoggerFactory.getLogger(Start.class);
private static final int DEFAULT_PORT = 8080;
private static final String CONTEXT_PATH = "/";
private static final String CONFIG_LOCATION = AppConfig.class.getName();
private static final String MAPPING_URL = "/*";

/*
* This application runs a Jetty webcontainer that runs the
* Spring Dispatcher Servlet.
*/
public static void main(String[] args) throws Exception {
new Start().startJetty(getPortFromArgs(args));
}

private static int getPortFromArgs(String[] args) {
if (args.length > 0) {
try {
return Integer.parseInt(args[0]);
} catch (NumberFormatException ignore) {
}
}
logger.info("No server port configured, falling back to {}", DEFAULT_PORT);
return DEFAULT_PORT;
}

private void startJetty(int port) throws Exception {
logger.info("Starting server at port {}", port);
Server server = new Server(port);
server.setHandler(getServletContextHandler(getContext()));
server.start();
logger.info("Server started at port {}", port);
server.join();
}

private static ServletContextHandler getServletContextHandler(WebApplicationContext context) {
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setErrorHandler(null);
contextHandler.setContextPath(CONTEXT_PATH);
contextHandler.addServlet(new ServletHolder(new DispatcherServlet(context)), MAPPING_URL);
contextHandler.addEventListener(new ContextLoaderListener(context));
return contextHandler;
}

private static WebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(CONFIG_LOCATION);
return context;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.baeldung.spring.actuator;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration {

@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry
.addViewController("/")
.setViewName("redirect:/actuator");
}
};
}

}
2 changes: 2 additions & 0 deletions spring-actuator/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always