Created
October 18, 2012 16:53
-
-
Save dwelch2344/3913226 to your computer and use it in GitHub Desktop.
Pragmatically add Spring MVC Controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package foobar; | |
| import org.springframework.stereotype.Controller; | |
| import org.springframework.ui.Model; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| @Controller | |
| public class TestController { | |
| @RequestMapping("/test/foobar") | |
| public String getSecureTest(Model model) { | |
| return "test"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import org.springframework.beans.BeansException; | |
| import org.springframework.beans.factory.annotation.Autowire; | |
| import org.springframework.beans.factory.config.BeanDefinition; | |
| import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | |
| import org.springframework.beans.factory.support.BeanDefinitionRegistry; | |
| import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; | |
| import org.springframework.beans.factory.support.RootBeanDefinition; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.context.annotation.Configuration; | |
| import org.springframework.context.annotation.ImportResource; | |
| import foobar.TestController; | |
| @Configuration | |
| public class ExampleConfig implements BeanDefinitionRegistryPostProcessor{ | |
| @Override | |
| public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} | |
| @Override | |
| public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { | |
| BeanDefinition beanDefinition = new RootBeanDefinition(TestController.class, Autowire.BY_TYPE.value(), true); | |
| registry.registerBeanDefinition("testController", beanDefinition); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment