Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created October 18, 2012 16:53
Show Gist options
  • Save dwelch2344/3913226 to your computer and use it in GitHub Desktop.
Save dwelch2344/3913226 to your computer and use it in GitHub Desktop.
Pragmatically add Spring MVC Controllers
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";
}
}
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