set parent config
ConfigurableApplicationContext - интерестный интерфейс, позволяющий
соединять разные конфигурации через определения родителя.
Например так:
```
ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
ConfigurableApplicationContext cac = new AnnotationConfigApplicationContext(SpringNewConfig.class);
cac.setParent(ctx);
cac.start();
CoolObj obj = cac.getBean("cool", CoolObj.class);
```
This commit is contained in:
@@ -11,6 +11,8 @@ import org.eclipse.jetty.util.log.Log;
|
|||||||
import org.eclipse.jetty.util.log.Slf4jLog;
|
import org.eclipse.jetty.util.log.Slf4jLog;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.web.context.ContextLoaderListener;
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
@@ -22,6 +24,8 @@ public class WebApp {
|
|||||||
private final Logger logger = LoggerFactory.getLogger(WebApp.class);
|
private final Logger logger = LoggerFactory.getLogger(WebApp.class);
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext rootContext;
|
||||||
|
|
||||||
public WebApp(String host, int port) {
|
public WebApp(String host, int port) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
@@ -51,6 +55,7 @@ public class WebApp {
|
|||||||
|
|
||||||
private WebApplicationContext getContext() {
|
private WebApplicationContext getContext() {
|
||||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
context.setParent(rootContext);
|
||||||
context.setConfigLocation("kinosearch.webapp");
|
context.setConfigLocation("kinosearch.webapp");
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user