Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- SQL
- Eclipse
- hadoop
- NPM
- window
- mybatis
- tomcat
- 보조정렬
- es6
- SSL
- vaadin
- Spring
- plugin
- JavaScript
- R
- mapreduce
- react
- Android
- xPlatform
- Sqoop
- Java
- MSSQL
- 공정능력
- Express
- IntelliJ
- table
- Kotlin
- GIT
- SPC
- Python
Archives
- Today
- Total
DBILITY
spring bean programmatically register to web applicaton context 본문
java/spring
spring bean programmatically register to web applicaton context
DBILITY 2016. 10. 24. 16:46반응형
제목 그대로 빈을 등록합니다.
2번의 경우 Object만 property setting이 가능하므로, 3번 구현 예가 실제 상황에선 더 적합합니다.
Spring 3.1.1에서 테스트되었으며, cglib dependancy가 필요합니다.
- controller 예
@Controller public class TestController { private static final Logger LOG = LoggerFactory.getLogger(TestController.class); @RequestMapping(value="/test.action") public void dummyMethod(HttpServletRequest request) throws Exception { LOG.debug("{} ----------------------------> {}",getClass(),request); } }
- 구현 예 1
@Configuration public class beanRegister implements BeanDefinitionRegistryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { BeanDefinition beanDefinition = new RootBeanDefinition(TestController.class, Autowire.BY_TYPE.value(), true); beanDefinition.setAttribute("propertyName", ref-object); registry.registerBeanDefinition("testController", beanDefinition); } }
- 구현 예 2
@Configuration public class beanRegister implements BeanDefinitionRegistryPostProcessor { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(TestController.class); beanDefinition.setAutowireMode(Autowire.BY_TYPE.value()); beanDefinition.setDependencyCheck(1); beanDefinition.setAutowireCandidate(false); MutablePropertyValues values = new MutablePropertyValues(); values.addPropertyValue(new PropertyValue("propertyName", ref-object)); values.addPropertyValue(new PropertyValue("propertyName2", "value")); beanDefinition.setPropertyValues(values); registry.registerBeanDefinition("testController", beanDefinition); } }
- mvc dispatcher에 bean을 설정합니다.
반응형
'java > spring' 카테고리의 다른 글
Spring Dispatcher Servlet workflow (0) | 2017.09.07 |
---|---|
PropertyPlaceholder에 ARIA Crypto 적용하기 (0) | 2017.09.07 |
logback에서 springframework log가 출력되지 않을때 (0) | 2016.10.21 |
spring mybatis stored procedure ( oracle ) (0) | 2016.09.24 |
java spring cron expression (0) | 2016.09.20 |
Comments