Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL_3301_testing_@ConfigurationProperties
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
<module>spring-boot</module>
|
||||
<module>spring-boot-admin</module>
|
||||
<module>spring-boot-angular</module>
|
||||
<module>spring-boot-annotations</module>
|
||||
<module>spring-boot-artifacts</module>
|
||||
<module>spring-boot-autoconfiguration</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
## Spring Boot Annotations
|
||||
|
||||
This module contains articles about Spring Boot annotations
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Spring Boot Annotations](https://www.baeldung.com/spring-boot-annotations)
|
||||
- [Spring Scheduling Annotations](https://www.baeldung.com/spring-scheduling-annotations)
|
||||
- [Spring Web Annotations](https://www.baeldung.com/spring-mvc-annotations)
|
||||
- [Spring Core Annotations](https://www.baeldung.com/spring-core-annotations)
|
||||
- [Spring Bean Annotations](https://www.baeldung.com/spring-bean-annotations)
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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-boot-annotations</artifactId>
|
||||
<name>spring-boot-annotations</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Test -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -6,16 +6,8 @@ This module contains articles about Spring Web MVC in Spring Boot projects.
|
||||
|
||||
- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon)
|
||||
- [Custom Validation MessageSource in Spring Boot](https://www.baeldung.com/spring-custom-validation-message-source)
|
||||
- [Spring Boot Annotations](https://www.baeldung.com/spring-boot-annotations)
|
||||
- [Spring Scheduling Annotations](https://www.baeldung.com/spring-scheduling-annotations)
|
||||
- [Spring Web Annotations](https://www.baeldung.com/spring-mvc-annotations)
|
||||
- [Spring Core Annotations](https://www.baeldung.com/spring-core-annotations)
|
||||
- [Display RSS Feed with Spring MVC](https://www.baeldung.com/spring-mvc-rss-feed)
|
||||
- [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao)
|
||||
- [Cache Eviction in Spring Boot](https://www.baeldung.com/spring-boot-evict-cache)
|
||||
- [Setting Up Swagger 2 with a Spring REST API](https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api)
|
||||
- [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally)
|
||||
- [Accessing Spring MVC Model Objects in JavaScript](https://www.baeldung.com/spring-mvc-model-objects-js)
|
||||
- [Using Spring ResponseEntity to Manipulate the HTTP Response](https://www.baeldung.com/spring-response-entity)
|
||||
- [Spring Bean Annotations](https://www.baeldung.com/spring-bean-annotations)
|
||||
- More articles: [[next -->]](/spring-boot-mvc-2)
|
||||
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.baeldung.accessparamsjs;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.accessparamsjs;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* Sample rest controller for the tutorial article
|
||||
* "Access Spring MVC Model object in JavaScript".
|
||||
*
|
||||
* @author Andrew Shcherbakov
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class Controller {
|
||||
|
||||
/**
|
||||
* Define two model objects (one integer and one string) and pass them to the view.
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/index")
|
||||
public ModelAndView thymeleafView(Map<String, Object> model) {
|
||||
model.put("number", 1234);
|
||||
model.put("message", "Hello from Spring MVC");
|
||||
return new ModelAndView("thymeleaf/index");
|
||||
}
|
||||
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
@Configuration
|
||||
public class ScheduleJobsByProfile {
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(ScheduleJobsByProfile.class);
|
||||
|
||||
@Profile("prod")
|
||||
@Bean
|
||||
public ScheduledJob scheduledJob()
|
||||
{
|
||||
return new ScheduledJob("@Profile");
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
public class ScheduledJob {
|
||||
|
||||
private String source;
|
||||
|
||||
public ScheduledJob(String source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(ScheduledJob.class);
|
||||
|
||||
@Scheduled(fixedDelay = 60000)
|
||||
public void cleanTempDir() {
|
||||
LOG.info("Cleaning temp directory via {}", source);
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
public class ScheduledJobsWithBoolean {
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(ScheduledJobsWithBoolean.class);
|
||||
|
||||
@Value("${jobs.enabled:true}")
|
||||
private boolean isEnabled;
|
||||
|
||||
/**
|
||||
* A scheduled job controlled via application property. The job always
|
||||
* executes, but the logic inside is protected by a configurable boolean
|
||||
* flag.
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60000)
|
||||
public void cleanTempDirectory() {
|
||||
if(isEnabled) {
|
||||
LOG.info("Cleaning temp directory via boolean flag");
|
||||
}
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ScheduledJobsWithConditional
|
||||
{
|
||||
/**
|
||||
* This uses @ConditionalOnProperty to conditionally create a bean, which itself
|
||||
* is a scheduled job.
|
||||
* @return ScheduledJob
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "jobs.enabled", matchIfMissing = true, havingValue = "true")
|
||||
public ScheduledJob runMyCronTask() {
|
||||
return new ScheduledJob("@ConditionalOnProperty");
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
public class ScheduledJobsWithExpression
|
||||
{
|
||||
private final static Logger LOG =
|
||||
LoggerFactory.getLogger(ScheduledJobsWithExpression.class);
|
||||
|
||||
/**
|
||||
* A scheduled job controlled via application property. The job always
|
||||
* executes, but the logic inside is protected by a configurable boolean
|
||||
* flag.
|
||||
*/
|
||||
@Scheduled(cron = "${jobs.cronSchedule:-}")
|
||||
public void cleanTempDirectory() {
|
||||
LOG.info("Cleaning temp directory via placeholder");
|
||||
}
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.scheduling;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
public class SchedulingApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SchedulingApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Access Spring MVC params</title>
|
||||
<script src="/js/jquery.js"></script>
|
||||
<script src="/js/script-async.js"></script>
|
||||
<script src="/js/script-async-jquery.js"></script>
|
||||
<script>
|
||||
var number = [[${number}]];
|
||||
var message = "[[${message}]]";
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
Number=
|
||||
<span th:text="${number}" th:remove="tag"></span>
|
||||
<br /> Message=
|
||||
<span th:text="${message}" th:remove="tag"></span>
|
||||
<h2>Data from the external JS file (due to loading order)</h2>
|
||||
<div id="number-ext"></div>
|
||||
<div id="message-ext"></div>
|
||||
<h2>Asynchronous loading from external JS file (plain JS)</h2>
|
||||
<div id="number-async"></div>
|
||||
<div id="message-async"></div>
|
||||
<h2>Asynchronous loading from external JS file (jQuery)</h2>
|
||||
<div id="number-async-jquery"></div>
|
||||
<div id="message-async-jquery"></div>
|
||||
</body>
|
||||
<script src="/js/script.js"></script>
|
||||
</html>
|
||||
File diff suppressed because one or more lines are too long
@@ -1,6 +0,0 @@
|
||||
$(function() {
|
||||
var node1 = document.createTextNode("message = " + message);
|
||||
var node2 = document.createTextNode("number = " + number);
|
||||
document.getElementById('message-async-jquery').append(node1);
|
||||
document.getElementById('number-async-jquery').append(node2);
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
window.onload = function() {
|
||||
var node1 = document.createTextNode("message = " + message);
|
||||
var node2 = document.createTextNode("number = " + number);
|
||||
document.getElementById('message-async').append(node1);
|
||||
document.getElementById('number-async').append(node2);
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
var node1 = document.createTextNode("message = " + message);
|
||||
var node2 = document.createTextNode("number = " + number);
|
||||
document.getElementById('message-ext').append(node1);
|
||||
document.getElementById('number-ext').append(node2);
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.accessparamsjs;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class ControllerUnitTest {
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void whenRequestThymeleaf_thenStatusOk() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/index")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
application-version=@project.version@
|
||||
application-version=@project.version@
|
||||
application-description=@project.description@
|
||||
+1
-1
@@ -18,7 +18,7 @@ class BuildInfoServiceIntegrationTest {
|
||||
|
||||
@Test
|
||||
void whenGetApplicationDescription_thenSuccess() {
|
||||
assertThat(service.getApplicationDescription(), Matchers.is("This is simple boot application for Spring boot actuator test"));
|
||||
assertThat(service.getApplicationDescription(), Matchers.is("Spring Boot Properties Module"));
|
||||
assertThat(service.getApplicationVersion(), Matchers.is("0.0.1-SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user