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>
|
||||
@@ -42,6 +43,7 @@
|
||||
<module>spring-boot-mvc-2</module>
|
||||
<module>spring-boot-mvc-birt</module>
|
||||
<module>spring-boot-nashorn</module>
|
||||
<module>spring-boot-parent</module>
|
||||
<module>spring-boot-performance</module>
|
||||
<module>spring-boot-properties</module>
|
||||
<module>spring-boot-property-exp</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
-5
@@ -16,11 +16,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
public class Swagger2Config {
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.baeldung.swagger2boot.controller"))
|
||||
.paths(PathSelectors.regex("/.*"))
|
||||
.build()
|
||||
.apiInfo(apiEndPointsInfo());
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.apiInfo(apiEndPointsInfo());
|
||||
}
|
||||
|
||||
private ApiInfo apiEndPointsInfo() {
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.baeldung.swagger2boot.controller;
|
||||
|
||||
import com.baeldung.swagger2boot.model.Foo;
|
||||
import com.baeldung.swagger2boot.model.User;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.websocket.server.PathParam;
|
||||
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
||||
|
||||
@Controller
|
||||
public class UserController {
|
||||
|
||||
public UserController() {
|
||||
super();
|
||||
} //@formatter:off
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "/createUser", produces = "application/json; charset=UTF-8")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@ResponseBody
|
||||
@ApiOperation(value = "Create user",
|
||||
notes = "This method creates a new user")
|
||||
public User createUser(@ApiParam(
|
||||
name = "firstName",
|
||||
type = "String",
|
||||
value = "First Name of the user",
|
||||
example = "Vatsal",
|
||||
required = true) @RequestParam String firstName) { //@formatter:on
|
||||
User user = new User(firstName);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.swagger2boot.model;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel
|
||||
public class User {
|
||||
|
||||
@ApiModelProperty(value = "first name of the user", name = "firstName", dataType = "String", example = "Vatsal")
|
||||
String firstName;
|
||||
|
||||
public User() {
|
||||
super();
|
||||
}
|
||||
|
||||
public User(final String firstName) {
|
||||
super();
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
## Spring Boot Parent
|
||||
|
||||
This module contains articles about Spring Boot Starter Parent
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- [The Spring Boot Starter Parent](https://www.baeldung.com/spring-boot-starter-parent)
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>spring-boot-parent</name>
|
||||
<packaging>pom</packaging>
|
||||
<description>spring-boot-parent</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
||||
<artifactId>spring-boot-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>spring-boot-with-starter-parent</module>
|
||||
<module>spring-boot-with-custom-parent</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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-with-custom-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>spring-boot-with-custom-parent</name>
|
||||
|
||||
<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.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.customparent;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootStarterCustomParentApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootStarterCustomParentApplication.class, args);
|
||||
System.out.println("Spring boot application running without starter parent");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>spring-boot-with-starter-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>spring-boot-with-starter-parent</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-boot.version>2.1.5.RELEASE</spring-boot.version>
|
||||
<junit.version>4.11</junit.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.starterparent;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootStarterParentApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootStarterParentApplication.class, args);
|
||||
System.out.println("Spring boot application running with starter parent");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,3 +31,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
|
||||
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
|
||||
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
|
||||
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {TestConfiguration1.class, TestConfiguration2.class}, properties = {"spring.main.allow-bean-definition-overriding=true"})
|
||||
public class SpringBootBeanDefinitionOverrideExceptionIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Test
|
||||
public void whenBeanOverridingAllowed_thenTestBean2OverridesTestBean1() {
|
||||
Object testBean = applicationContext.getBean("testBean");
|
||||
|
||||
assertThat(testBean.getClass()).isEqualTo(TestConfiguration2.TestBean2.class);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class TestConfiguration1 {
|
||||
|
||||
class TestBean1 {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean1 testBean() {
|
||||
return new TestBean1();
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.beandefinitionoverrideexception;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class TestConfiguration2 {
|
||||
|
||||
class TestBean2 {
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TestBean2 testBean() {
|
||||
return new TestBean2();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user