本文整理汇总了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);
}
示例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);
}
}
示例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.");
}
}
}
示例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();
}
示例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);
}
示例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}");
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}