diff --git a/parent-boot-3/pom.xml b/parent-boot-3/pom.xml index ff615a565466..66dbc0d13196 100644 --- a/parent-boot-3/pom.xml +++ b/parent-boot-3/pom.xml @@ -227,7 +227,7 @@ 3.2.0 3.12.1 3.3.0 - 3.3.2 + 3.4.0 5.11.0-M2 0.9.17 diff --git a/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/Application.java b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/Application.java index 196f8bf3d248..881425f05f47 100644 --- a/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/Application.java +++ b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/Application.java @@ -2,14 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.actuator") +@SpringBootApplication(scanBasePackages = "com.baeldung.actuator") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } -} +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/JobConfig.java b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/JobConfig.java new file mode 100644 index 000000000000..1721e4c118a8 --- /dev/null +++ b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/JobConfig.java @@ -0,0 +1,29 @@ +package com.baeldung.actuator; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; + +@Configuration +@EnableScheduling +public class JobConfig { + + @Scheduled(fixedDelay = 1000L) + public void scheduleFixedDelayTask() { + System.out.println( + "Fixed delay task - " + System.currentTimeMillis() / 1000); + } + + @Scheduled(fixedRate = 1000L) + public void scheduleFixedRateTask() { + System.out.println( + "Fixed rate task - " + System.currentTimeMillis() / 1000); + } + + @Scheduled(cron = "0 15 10 15 * ?") + public void scheduleTaskUsingCronExpression() { + long now = System.currentTimeMillis() / 1000; + System.out.println( + "schedule tasks using cron jobs - " + now); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/SecurityConfig.java b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/SecurityConfig.java new file mode 100644 index 000000000000..cd56067dd139 --- /dev/null +++ b/spring-boot-modules/spring-boot-simple/src/main/java/com/baeldung/actuator/SecurityConfig.java @@ -0,0 +1,21 @@ +package com.baeldung.actuator; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + @Bean + public SecurityFilterChain securityWebFilterChain(HttpSecurity http) throws Exception { + return http + .authorizeHttpRequests(auth -> auth + .requestMatchers("/actuator/**").permitAll() + .anyRequest().authenticated()) + .build(); + } +} \ No newline at end of file