BAEL-20863 Move Spring Boot CTX Fluent module
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>spring-boot-ctx-fluent</module>
|
||||
<module>spring-boot-data</module>
|
||||
<module>spring-boot-mvc-birt</module>
|
||||
<module>spring-boot-properties</module>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
## Spring Boot Context Fluent
|
||||
|
||||
This module contains articles about Spring Boot Fluent Builder
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Context Hierarchy with the Spring Boot Fluent Builder API](https://www.baeldung.com/spring-boot-context-hierarchy)
|
||||
@@ -0,0 +1,24 @@
|
||||
<?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-ctx-fluent</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-boot-ctx-fluent</name>
|
||||
<packaging>jar</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.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.ctx1;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
import com.baeldung.parent.IHomeService;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.ctx1")
|
||||
@PropertySource("classpath:ctx1.properties")
|
||||
@EnableAutoConfiguration
|
||||
public class Ctx1Config {
|
||||
|
||||
@Bean
|
||||
public IHomeService homeService() {
|
||||
return new GreetingService();
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.ctx1;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.baeldung.parent.IHomeService;
|
||||
|
||||
@Controller
|
||||
public class Ctx1Controller {
|
||||
|
||||
@Autowired
|
||||
IHomeService homeService;
|
||||
|
||||
@GetMapping("/home")
|
||||
@ResponseBody
|
||||
public String greeting() {
|
||||
|
||||
return homeService.getGreeting();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.ctx1;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.parent.IHomeService;
|
||||
|
||||
@Service
|
||||
public class GreetingService implements IHomeService {
|
||||
|
||||
public String getGreeting() {
|
||||
return "Greetings for the day";
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.ctx2;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.ctx2")
|
||||
@EnableAutoConfiguration
|
||||
@PropertySource("classpath:ctx2.properties")
|
||||
public class Ctx2Config {
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.ctx2;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baeldung.parent.IHomeService;
|
||||
|
||||
@RestController
|
||||
public class Ctx2Controller {
|
||||
|
||||
@Autowired
|
||||
IHomeService homeService;
|
||||
|
||||
@GetMapping(value = "/greeting", produces = "application/json")
|
||||
public String getGreeting() {
|
||||
return homeService.getGreeting();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.parent;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
import com.baeldung.ctx1.Ctx1Config;
|
||||
import com.baeldung.ctx2.Ctx2Config;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder().parent(ParentConfig.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.child(Ctx1Config.class)
|
||||
.web(WebApplicationType.SERVLET)
|
||||
.sibling(Ctx2Config.class)
|
||||
.web(WebApplicationType.SERVLET)
|
||||
.run(args);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.parent;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class HomeService implements IHomeService {
|
||||
|
||||
public String getGreeting() {
|
||||
return "Welcome User";
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.parent;
|
||||
|
||||
public interface IHomeService {
|
||||
|
||||
String getGreeting();
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.parent;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan("com.baeldung.parent")
|
||||
public class ParentConfig {}
|
||||
@@ -0,0 +1,5 @@
|
||||
server.port=8081
|
||||
server.servlet.context-path=/ctx1
|
||||
#logging.level=debug
|
||||
spring.application.admin.enabled=false
|
||||
spring.application.admin.jmx-name=org.springframework.boot:type=AdminRest,name=SpringRestApplication
|
||||
@@ -0,0 +1,5 @@
|
||||
server.port=8082
|
||||
server.servlet.context-path=/ctx2
|
||||
|
||||
spring.application.admin.enabled=false
|
||||
spring.application.admin.jmx-name=org.springframework.boot:type=WebAdmin,name=SpringWebApplication
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package org.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.parent.App;
|
||||
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public final void testMain() throws Exception {
|
||||
App.main(new String[] {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user