當前位置: 首頁>>代碼示例>>Java>>正文


Java WebApplicationContext類代碼示例

本文整理匯總了Java中org.springframework.web.context.WebApplicationContext的典型用法代碼示例。如果您正苦於以下問題:Java WebApplicationContext類的具體用法?Java WebApplicationContext怎麽用?Java WebApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebApplicationContext類屬於org.springframework.web.context包,在下文中一共展示了WebApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartup

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	WebApplicationContext context = getContext();
	servletContext.addListener(new ContextLoaderListener(context));
	servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter("UTF-8"));

	DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
	dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("Dispatcher", dispatcherServlet);
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/*");

	CXFServlet cxf = new CXFServlet();
	BusFactory.setDefaultBus(cxf.getBus());
	ServletRegistration.Dynamic cxfServlet = servletContext.addServlet("CXFServlet", cxf);
	cxfServlet.setLoadOnStartup(1);
	cxfServlet.addMapping("/services/*");

	servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false,
			"/*");

	servletContext.getSessionCookieConfig().setSecure(cookieSecure);
}
 
開發者ID:esig,項目名稱:dss-demonstrations,代碼行數:25,代碼來源:AppInitializer.java

示例2: init

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
public void init(ServletConfig config) throws ServletException {
    try {
        WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
        final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
        beanFactory.autowireBean(this);
    }
    catch (Exception e) {
        logger.error("Error initializing ShibbolethExtAuthnHandler", e);
    }
}
 
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:11,代碼來源:ShibbolethExtAuthnHandler.java

示例3: processInjectionBasedOnCurrentContext

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
/**
 * Process {@code @Autowired} injection for the given target object,
 * based on the current web application context.
 * <p>Intended for use as a delegate.
 * @param target the target object to process
 * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext()
 */
public static void processInjectionBasedOnCurrentContext(Object target) {
	Assert.notNull(target, "Target object must not be null");
	WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext();
	if (cc != null) {
		AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
		bpp.setBeanFactory(cc.getAutowireCapableBeanFactory());
		bpp.processInjection(target);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Current WebApplicationContext is not available for processing of " +
					ClassUtils.getShortName(target.getClass()) + ": " +
					"Make sure this class gets constructed in a Spring web application. Proceeding without injection.");
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:SpringBeanAutowiringSupport.java

示例4: trigger

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
/**
    * See {@link IEventNotificationService#trigger(String, String, Long, String, String)
    */
   private void trigger(Event event, String subject, String message) {
final String subjectToSend = subject == null ? event.getSubject() : subject;
final String messageToSend = message == null ? event.getMessage() : message;

// create a new thread to send the messages as it can take some time
new Thread(() -> {
    try {
	HibernateSessionManager.openSession();
	// use proxy bean instead of concrete implementation of service
	// otherwise there is no transaction for the new session
	WebApplicationContext ctx = WebApplicationContextUtils
		.getWebApplicationContext(SessionManager.getServletContext());
	IEventNotificationService eventNotificationService = (IEventNotificationService) ctx
		.getBean("eventNotificationService");
	eventNotificationService.triggerInternal(event, subjectToSend, messageToSend);
    } finally {
	HibernateSessionManager.closeSession();
    }
}).start();
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:24,代碼來源:EventNotificationService.java

示例5: doFilter

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	// Lazily initialize the delegate if necessary.
	Filter delegateToUse = this.delegate;
	if (delegateToUse == null) {
		synchronized (this.delegateMonitor) {
			if (this.delegate == null) {
				WebApplicationContext wac = findWebApplicationContext();
				if (wac == null) {
					throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
				}
				this.delegate = initDelegate(wac);
			}
			delegateToUse = this.delegate;
		}
	}

	// Let the delegate perform the actual doFilter operation.
	invokeDelegate(delegateToUse, request, response, filterChain);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:DelegatingFilterProxy.java

示例6: before

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
@Override
protected void before() throws Throwable {

	final SpringApplicationBuilder builder = new SpringApplicationBuilder(LocalTestSkipperServer.class);

	if (this.configLocations  != null && this.configLocations.length > 0) {
		builder.properties(
			String.format("spring.config.location:%s", StringUtils.arrayToCommaDelimitedString(this.configLocations))
		);
	}

	if (this.configNames  != null && this.configNames.length > 0) {
		builder.properties(
			String.format("spring.config.name:%s", StringUtils.arrayToCommaDelimitedString(this.configNames))
		);
	}

	this.app = builder.build();



	configurableApplicationContext = app.run(
		new String[] { "--server.port=0" });

	Collection<Filter> filters = configurableApplicationContext.getBeansOfType(Filter.class).values();
	mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) configurableApplicationContext)
			.addFilters(filters.toArray(new Filter[filters.size()])).build();
	skipperPort = configurableApplicationContext.getEnvironment().resolvePlaceholders("${server.port}");
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:30,代碼來源:LocalSkipperResource.java

示例7: getForumManager

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
private IForumService getForumManager() {
if (forumService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    forumService = (IForumService) wac.getBean(ForumConstants.FORUM_SERVICE);
}
return forumService;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:AuthoringAction.java

示例8: getLessonService

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
private ILessonService getLessonService() {
if (OrganisationGroupAction.lessonService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    OrganisationGroupAction.lessonService = (ILessonService) ctx.getBean("lessonService");
}
return OrganisationGroupAction.lessonService;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:OrganisationGroupAction.java

示例9: unspecified

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
@Override
   public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
HttpSession ss = SessionManager.getSession();
UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER);
long toolSessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID);

WebApplicationContext wac = WebApplicationContextUtils
	.getRequiredWebApplicationContext(getServlet().getServletContext());
ILearnerService learnerService = (ILearnerService) wac.getBean("learnerService");
String finishURL = learnerService.completeToolSession(toolSessionId, user.getUserID().longValue());
return new RedirectingActionForward(finishURL);
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:LearningAction.java

示例10: getUserManagementService

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
private IUserManagementService getUserManagementService() {
if (HomeAction.userManagementService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.userManagementService = (IUserManagementService) ctx.getBean("userManagementService");
}
return HomeAction.userManagementService;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:HomeAction.java

示例11: getLearningDesignService

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
private ILearningDesignService getLearningDesignService() {
if (HomeAction.learningDesignService == null) {
    WebApplicationContext ctx = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    HomeAction.learningDesignService = (ILearningDesignService) ctx.getBean("learningDesignService");
}
return HomeAction.learningDesignService;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:HomeAction.java

示例12: getUserManagementService

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
private IUserManagementService getUserManagementService() {
if (AuthoringAction.userManagementService == null) {
    WebApplicationContext wac = WebApplicationContextUtils
	    .getRequiredWebApplicationContext(getServlet().getServletContext());
    AuthoringAction.userManagementService = (IUserManagementService) wac
	    .getBean(CentralConstants.USER_MANAGEMENT_SERVICE_BEAN_NAME);
}
return AuthoringAction.userManagementService;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:AuthoringAction.java

示例13: main

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
/**
 * Sets up and runs server.
 * @param args
 */
public static void main(String[] args)
{
    final Server server = new Server();

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(8080);
    server.addConnector(connector);

    Context htmlContext = new Context(server, "/", Context.SESSIONS);

    ResourceHandler htmlHandler = new ResourceHandler();
    htmlHandler.setResourceBase("web");
    htmlContext.setHandler(htmlHandler);

    Context servletContext = new Context(server, "/", Context.SESSIONS);

    GenericWebApplicationContext springContext = new GenericWebApplicationContext();
    springContext.setParent(new ClassPathXmlApplicationContext("org/getahead/dwrdemo/cli/spring.xml"));
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, springContext);

    ServletHolder holder = new ServletHolder(new DwrSpringServlet());
    holder.setInitParameter("pollAndCometEnabled", "true");
    holder.setInitParameter("debug", "true");
    servletContext.addServlet(holder, "/dwr/*");

    try
    {
        JettyShutdown.addShutdownHook(server);
        server.start();
        server.join();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:41,代碼來源:JettySpringLauncher.java

示例14: putActivityPositionInRequestByToolSessionId

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
/**
    * Finds activity position within Learning Design and stores it as request attribute.
    */
   public static ActivityPositionDTO putActivityPositionInRequestByToolSessionId(Long toolSessionId,
    HttpServletRequest request, ServletContext context) {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
ILearnerService learnerService = (ILearnerService) wac.getBean("learnerService");
if (learnerService == null) {
    LearningWebUtil.log.warn("Can not set activity position, no Learner service in servlet context.");
    return null;
}
ActivityPositionDTO positionDTO = learnerService.getActivityPositionByToolSessionId(toolSessionId);
if (positionDTO != null) {
    request.setAttribute(AttributeNames.ATTR_ACTIVITY_POSITION, positionDTO);
}
return positionDTO;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:LearningWebUtil.java

示例15: lookupSessionFactory

import org.springframework.web.context.WebApplicationContext; //導入依賴的package包/類
/**
 * Look up the SessionFactory that this filter should use.
 * <p>The default implementation looks for a bean with the specified name
 * in Spring's root application context.
 * @return the SessionFactory to use
 * @see #getSessionFactoryBeanName
 */
protected SessionFactory lookupSessionFactory() {
	if (logger.isDebugEnabled()) {
		logger.debug("Using SessionFactory '" + getSessionFactoryBeanName() + "' for OpenSessionInViewFilter");
	}
	WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
	return wac.getBean(getSessionFactoryBeanName(), SessionFactory.class);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:OpenSessionInViewFilter.java


注:本文中的org.springframework.web.context.WebApplicationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。