BAEL-20863 Move Spring Boot CTX Fluent module

This commit is contained in:
mikr
2020-01-28 12:52:49 +01:00
parent b168a23f54
commit 1c4bef08ab
17 changed files with 2 additions and 3 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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";
}
}

View File

@@ -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 {
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -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";
}
}

View File

@@ -0,0 +1,6 @@
package com.baeldung.parent;
public interface IHomeService {
String getGreeting();
}

View File

@@ -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 {}

View File

@@ -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

View File

@@ -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

View File

@@ -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>

View File

@@ -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[] {});
}
}