org.springframework.web.context.support.AnnotationConfigWebApplicationContext Java Examples

The following examples show how to use org.springframework.web.context.support.AnnotationConfigWebApplicationContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSockJsIntegrationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() throws Exception {
	logger.debug("Setting up '" + this.testName.getMethodName() + "'");
	this.testFilter = new TestFilter();

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(TestConfig.class, upgradeStrategyConfigClass());

	this.server = createWebSocketTestServer();
	this.server.setup();
	this.server.deployConfig(this.wac, this.testFilter);
	this.server.start();

	this.wac.setServletContext(this.server.getServletContext());
	this.wac.refresh();

	this.baseUrl = "http://localhost:" + this.server.getPort();
}
 
Example #2
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #3
Source File: HandlerMappingIntrospectorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void getCorsConfigurationPreFlight() throws Exception {
	AnnotationConfigWebApplicationContext cxt = new AnnotationConfigWebApplicationContext();
	cxt.register(TestConfig.class);
	cxt.refresh();

	// PRE-FLIGHT

	MockHttpServletRequest request = new MockHttpServletRequest("OPTIONS", "/path");
	request.addHeader("Origin", "http://localhost:9000");
	request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "POST");
	CorsConfiguration corsConfig = getIntrospector(cxt).getCorsConfiguration(request);

	assertNotNull(corsConfig);
	assertEquals(Collections.singletonList("http://localhost:9000"), corsConfig.getAllowedOrigins());
	assertEquals(Collections.singletonList("POST"), corsConfig.getAllowedMethods());
}
 
Example #4
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static void createAndStartServer() {
  server = new Server(HTTP_SERVER_PORT);

  HashSessionIdManager idmanager = new HashSessionIdManager();
  server.setSessionIdManager(idmanager);

  AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
  applicationContext.register(JPAApplicationConfiguration.class);
  applicationContext.refresh();

  appContext = applicationContext;

  try {
    server.setHandler(getServletContextHandler(applicationContext));
    server.start();
  } catch (Exception e) {
    log.error("Error starting server", e);
  }
}
 
Example #5
Source File: SpringWebinitializer.java    From Spring-5.0-Cookbook with MIT License 6 votes vote down vote up
private void addDispatcherContext(ServletContext container) {
	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
	dispatcherContext.register(SpringDispatcherConfig.class);

	// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
	ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
			new DispatcherServlet(dispatcherContext));
	dispatcher.addMapping("*.html");
	dispatcher.setLoadOnStartup(1);

	FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
	corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
	corsFilter.addMappingForUrlPatterns(null, true, "/*");

	FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
	filter.addMappingForServletNames(null, true, "/*");

	FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
	multipartFilter.addMappingForUrlPatterns(null, true, "/*");

}
 
Example #6
Source File: AnnotationConfigDispatcherServletInitializerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void rootContextOnly() throws ServletException {
	initializer = new MyAnnotationConfigDispatcherServletInitializer() {
		@Override
		protected Class<?>[] getRootConfigClasses() {
			return new Class<?>[] {MyConfiguration.class};
		}
		@Override
		protected Class<?>[] getServletConfigClasses() {
			return null;
		}
	};

	initializer.onStartup(servletContext);

	DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
	servlet.init(new MockServletConfig(this.servletContext));

	WebApplicationContext wac = servlet.getWebApplicationContext();
	((AnnotationConfigWebApplicationContext) wac).refresh();

	assertTrue(wac.containsBean("bean"));
	assertTrue(wac.getBean("bean") instanceof MyBean);
}
 
Example #7
Source File: ViewResolutionIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
	String basePath = "org/springframework/web/servlet/config/annotation";
	MockServletContext servletContext = new MockServletContext(basePath);
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	MockHttpServletResponse response = new MockHttpServletResponse();

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(configClass);
	context.setServletContext(servletContext);
	context.refresh();
	DispatcherServlet servlet = new DispatcherServlet(context);
	servlet.init(servletConfig);
	servlet.service(request, response);
	return response;
}
 
Example #8
Source File: AbstractWebSocketIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setup() throws Exception {
	logger.debug("Setting up '" + this.testName.getMethodName() + "', client=" +
			this.webSocketClient.getClass().getSimpleName() + ", server=" +
			this.server.getClass().getSimpleName());

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(getAnnotatedConfigClasses());
	this.wac.register(upgradeStrategyConfigTypes.get(this.server.getClass()));

	if (this.webSocketClient instanceof Lifecycle) {
		((Lifecycle) this.webSocketClient).start();
	}

	this.server.setup();
	this.server.deployConfig(this.wac);
	this.server.start();

	this.wac.setServletContext(this.server.getServletContext());
	this.wac.refresh();
}
 
Example #9
Source File: Starter.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void startPeopleService() throws Exception {
    final File base = createBaseDirectory();
    log.info("Using base folder: " + base.getAbsolutePath());

    final Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir(base.getAbsolutePath());

    Context context = tomcat.addContext("/", base.getAbsolutePath());
    Tomcat.addServlet(context, "CXFServlet", new CXFServlet());

    context.addServletMapping("/rest/*", "CXFServlet");
    context.addApplicationListener(ContextLoaderListener.class.getName());
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));

    context.addParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.addParameter("contextConfigLocation", AppConfig.class.getName());

    tomcat.start();
    tomcat.getServer().await();
}
 
Example #10
Source File: AbstractNemServletContextListener.java    From nem.deploy with MIT License 6 votes vote down vote up
@Override
public void contextInitialized(final ServletContextEvent event) {
	try {
		final AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext();

		webCtx.register(this.webAppInitializerClass);
		webCtx.setParent(this.appCtx);

		final ServletContext context = event.getServletContext();
		this.initialize(webCtx, context);

		context.setInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");

		if (this.useDosFilter) {
			addDosFilter(context);
		}

		addGzipFilter(context);
		addCorsFilter(context);
	} catch (final Exception e) {
		throw new RuntimeException(String.format("Exception in contextInitialized: %s", e.toString()), e);
	}
}
 
Example #11
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #12
Source File: JPAWebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #13
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #14
Source File: ViewResolutionIntegrationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
	String basePath = "org/springframework/web/servlet/config/annotation";
	MockServletContext servletContext = new MockServletContext(basePath);
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	MockHttpServletResponse response = new MockHttpServletResponse();

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(configClass);
	context.setServletContext(servletContext);
	context.refresh();
	DispatcherServlet servlet = new DispatcherServlet(context);
	servlet.init(servletConfig);
	servlet.service(request, response);
	return response;
}
 
Example #15
Source File: MyWebAppInitializer.java    From spring-rest-server with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext container) {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    // Register application config
    rootContext.register(AppConfig.class);

    // Manage the lifecycle of the root application context
    container.addListener(new ContextLoaderListener(rootContext));

    // Register Encoding Filter
    addEncodingFilter(container);

    // Register Logging Filter
    addLoggingFilter(container);

    // Register and map the dispatcher servlet
    addServiceDispatcherServlet(container, rootContext);
}
 
Example #16
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #17
Source File: WebAppConfiguration.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setServletContext(servletContext);
    rootContext.register(ThymeleafConfig.class);

    servletContext.addListener(new SakaiContextLoaderListener(rootContext));

    servletContext.addFilter("sakai.request", RequestFilter.class)
            .addMappingForUrlPatterns(
                    EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
                    true,
                    "/*");

    Dynamic servlet = servletContext.addServlet("sakai.onedrive", new DispatcherServlet(rootContext));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
}
 
Example #18
Source File: WebAppConfiguration.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.setServletContext(servletContext);
	rootContext.register(ThymeleafConfig.class);

	servletContext.addListener(new ToolListener());
	servletContext.addListener(new SakaiContextLoaderListener(rootContext));

	servletContext.addFilter("sakai.request", RequestFilter.class)
		.addMappingForUrlPatterns(
			EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE),
			true,
			"/*");

	Dynamic servlet = servletContext.addServlet("sakai.datemanager", new DispatcherServlet(rootContext));
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
Example #19
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example #20
Source File: ViewResolutionIntegrationTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
	String basePath = "org/springframework/web/servlet/config/annotation";
	MockServletContext servletContext = new MockServletContext(basePath);
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	MockHttpServletResponse response = new MockHttpServletResponse();

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(configClass);
	context.setServletContext(servletContext);
	context.refresh();
	DispatcherServlet servlet = new DispatcherServlet(context);
	servlet.init(servletConfig);
	servlet.service(request, response);
	return response;
}
 
Example #21
Source File: MainWebAppInitializer.java    From tutorials with MIT License 5 votes vote down vote up
/**
 * Register and configure all Servlet container components necessary to power the web application.
 */
@Override
public void onStartup(final ServletContext sc) throws ServletException {
    System.out.println("MyWebAppInitializer.onStartup()");

    // Create the 'root' Spring application context
    final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
    root.scan("com.baeldung.config.parent");
    // root.getEnvironment().setDefaultProfiles("embedded");

    // Manages the lifecycle of the root application context
    sc.addListener(new ContextLoaderListener(root));

    // Handles requests into the application
    final AnnotationConfigWebApplicationContext childWebApplicationContext = new AnnotationConfigWebApplicationContext();
    childWebApplicationContext.scan("com.baeldung.config.child");
    final ServletRegistration.Dynamic appServlet = sc.addServlet("api", new DispatcherServlet(childWebApplicationContext));
    appServlet.setLoadOnStartup(1);
    final Set<String> mappingConflicts = appServlet.addMapping("/");
    if (!mappingConflicts.isEmpty()) {
        throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278");
    }

    // spring security filter
    final DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain");
    final Dynamic addedFilter = sc.addFilter("springSecurityFilterChain", springSecurityFilterChain);
    addedFilter.addMappingForUrlPatterns(null, false, "/*");
}
 
Example #22
Source File: PropertySources.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Check system properties and servlet context init params for an annotated Spring configuration
 * class located under {@code key}. If present, create a new
 * {@AnnotationConfigWebApplicationContext} and register
 * the annotated configuration class. Refresh the context and then examine it for a
 * {@code PropertySource<?>} bean. There must be exactly one {@code PropertySource<?>} bean
 * present in the application context.
 */
public static Optional<PropertySource<?>> getPropertySource(ServletContextEvent sce, String key) {
    Optional<String> annotatedClass = getProperty(sce, key);
    if (annotatedClass.isPresent()) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.setServletContext(sce.getServletContext());
        PropertySource<?> propertySource = getPropertySource(annotatedClass.get(), context);
        return Optional.<PropertySource<?>> of(propertySource);
    } else {
        return Optional.absent();
    }
}
 
Example #23
Source File: AppInitializer.java    From maven-framework-project with MIT License 5 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext webApplicationContext =
            new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(AppConfig.class);


    DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
    ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispatcherServlet", dispatcherServlet);
    dynamic.addMapping("/");

}
 
Example #24
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void contextDestroyed(ServletContextEvent sce) {
    LOGGER.info("Destroying Web application");
    WebApplicationContext ac = WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext());
    AnnotationConfigWebApplicationContext gwac = (AnnotationConfigWebApplicationContext) ac;
    gwac.close();
    LOGGER.debug("Web application destroyed");
}
 
Example #25
Source File: RequestPartIntegrationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startServer() throws Exception {
	// Let server pick its own random, available port.
	server = new Server(0);

	ServletContextHandler handler = new ServletContextHandler();
	handler.setContextPath("/");

	Class<?> config = CommonsMultipartResolverTestConfig.class;
	ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class);
	commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName());
	commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
	handler.addServlet(commonsResolverServlet, "/commons-resolver/*");

	config = StandardMultipartResolverTestConfig.class;
	ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class);
	standardResolverServlet.setInitParameter("contextConfigLocation", config.getName());
	standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
	standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
	handler.addServlet(standardResolverServlet, "/standard-resolver/*");

	server.setHandler(handler);
	server.start();

	Connector[] connectors = server.getConnectors();
	NetworkConnector connector = (NetworkConnector) connectors[0];
	baseUrl = "http://localhost:" + connector.getLocalPort();
}
 
Example #26
Source File: EndpointObfuscatorConfiguration.java    From joal with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean obfuscatedDispatcherServlet() {
    final DispatcherServlet dispatcherServlet = new DispatcherServlet();

    final ApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    dispatcherServlet.setApplicationContext(applicationContext);

    final ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(dispatcherServlet, "/" + this.pathPrefix + "/*");
    servletRegistrationBean.setName("joal");
    return servletRegistrationBean;
}
 
Example #27
Source File: AbstractAnnotationConfigDispatcherServletInitializer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>This implementation creates an {@link AnnotationConfigWebApplicationContext},
 * providing it the annotated classes returned by {@link #getServletConfigClasses()}.
 */
@Override
protected WebApplicationContext createServletApplicationContext() {
	AnnotationConfigWebApplicationContext servletAppContext = new AnnotationConfigWebApplicationContext();
	Class<?>[] configClasses = getServletConfigClasses();
	if (!ObjectUtils.isEmpty(configClasses)) {
		servletAppContext.register(configClasses);
	}
	return servletAppContext;
}
 
Example #28
Source File: WebInitializer.java    From springMvc4.x-project with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // ③
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
Example #29
Source File: BaseJPARestTestCase.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private static ServletContextHandler getServletContextHandler(AnnotationConfigWebApplicationContext context) throws IOException {
  ServletContextHandler contextHandler = new ServletContextHandler();
  JPAWebConfigurer configurer = new JPAWebConfigurer();
  configurer.setContext(context);
  contextHandler.addEventListener(configurer);

  // Create the SessionHandler (wrapper) to handle the sessions
  HashSessionManager manager = new HashSessionManager();
  SessionHandler sessions = new SessionHandler(manager);
  contextHandler.setHandler(sessions);

  return contextHandler;
}
 
Example #30
Source File: ApplicationConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean modelerApiServlet(ApplicationContext applicationContext) {
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(applicationContext);
    dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
    DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");
    registrationBean.setName("Flowable Modeler App API Servlet");
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    return registrationBean;
}