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


Java AnnotationConfigWebApplicationContext.refresh方法代碼示例

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


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

示例1: testCustomShellProperties

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void testCustomShellProperties() throws Exception {
	MockEnvironment env = new MockEnvironment();
	env.setProperty("management.shell.auth.type", "simple");
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.setEnvironment(env);
	ctx.setServletContext(new MockServletContext());
	ctx.register(TestShellConfiguration.class);
	ctx.register(CrshAutoConfiguration.class);
	ctx.refresh();

	PluginLifeCycle lifeCycle = ctx.getBean(PluginLifeCycle.class);
	String uuid = lifeCycle.getConfig().getProperty("test.uuid");
	assertThat(uuid).isEqualTo(TestShellConfiguration.uuid);
	ctx.close();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:ShellPropertiesTests.java

示例2: setup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Before
@SuppressWarnings("resource")
public void setup() throws Exception {
	this.filterChain = new MockFilterChain(this.servlet, new ResourceUrlEncodingFilter());

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(WebConfig.class);
	context.refresh();

	this.request = new MockHttpServletRequest("GET", "/");
	this.request.setContextPath("/myapp");
	this.response = new MockHttpServletResponse();

	Object urlProvider = context.getBean(ResourceUrlProvider.class);
	this.request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, urlProvider);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ResourceUrlProviderJavaConfigTests.java

示例3: testFromMappingName

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void testFromMappingName() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(WebConfig.class);
	context.refresh();

	this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	this.request.setServerName("example.org");
	this.request.setServerPort(9999);
	this.request.setContextPath("/base");

	String mappingName = "PAC#getAddressesForCountry";
	String url = MvcUriComponentsBuilder.fromMappingName(mappingName).arg(0, "DE").buildAndExpand(123);
	assertEquals("/base/people/123/addresses/DE", url);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:MvcUriComponentsBuilderTests.java

示例4: contextInitialized

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();

    LOGGER.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(ApplicationConfiguration.class);
    rootContext.refresh();

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);

    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);

    initSpring(servletContext, rootContext);
    initSpringSecurity(servletContext, disps);

    LOGGER.debug("Web application fully configured");
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:19,代碼來源:WebConfigurer.java

示例5: getToolContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(Config.class);
	context.refresh();
	EmbeddedVelocityToolboxView view = context
			.getBean(EmbeddedVelocityToolboxView.class);
	view.setToolboxConfigLocation(toolboxConfigLocation);
	Map<String, Object> model = new LinkedHashMap<String, Object>();
	HttpServletRequest request = new MockHttpServletRequest();
	HttpServletResponse response = new MockHttpServletResponse();
	ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
			response);
	context.close();
	return toolContext;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:EmbeddedVelocityToolboxViewTests.java

示例6: createAndStartServer

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
public static TestServer createAndStartServer(Class<?>... configClasses) {
    int port = NEXT_PORT.incrementAndGet();
    Server server = new Server(port);

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

    AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
    applicationContext.register(configClasses);
    applicationContext.refresh();

    try {
        server.setHandler(getServletContextHandler(applicationContext));
        server.start();
    } catch (Exception e) {
        LOGGER.error("Error starting server", e);
    }

    return new TestServer(server, applicationContext, port);
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:21,代碼來源:TestServerUtil.java

示例7: createLayoutFromConfigClass

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void createLayoutFromConfigClass() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	MockServletContext servletContext = new MockServletContext();
	context.setServletContext(servletContext);
	context.refresh();
	ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class)
			.resolveViewName("view", Locale.UK);
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	view.render(Collections.singletonMap("foo", "bar"), request, response);
	String result = response.getContentAsString();
	assertThat(result).contains("<title>Content</title>");
	assertThat(result).contains("<span>bar</span>");
	context.close();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:20,代碼來源:ThymeleafAutoConfigurationTests.java

示例8: testOpenEntityManagerInViewInterceptorCreated

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void testOpenEntityManagerInViewInterceptorCreated() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class, getAutoConfigureClass());
	context.refresh();
	assertThat(context.getBean(OpenEntityManagerInViewInterceptor.class)).isNotNull();
	context.close();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:10,代碼來源:AbstractJpaAutoConfigurationTests.java

示例9: load

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
private void load(Class<?> config, String... environment) {
	AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
	applicationContext.setServletContext(new MockServletContext());
	applicationContext.register(config, BaseConfiguration.class);
	EnvironmentTestUtils.addEnvironment(applicationContext, environment);
	applicationContext.refresh();
	this.context = applicationContext;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:9,代碼來源:RepositoryRestMvcAutoConfigurationTests.java

示例10: initContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
private ApplicationContext initContext(Class<?>... configClasses) {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(configClasses);
	context.refresh();
	return context;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:8,代碼來源:WebMvcConfigurationSupportTests.java

示例11: contextLoads

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void contextLoads() {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(TestConfig.class);
	context.setServletContext(new MockServletContext());
	context.refresh();

	MatcherAssert.assertThat(context.getBean("contentHandlerMapping"), CoreMatchers.is(CoreMatchers.not(CoreMatchers.nullValue())));
	MatcherAssert.assertThat(context.getBean("contentLinksProcessor"), CoreMatchers.is(CoreMatchers.not(CoreMatchers.nullValue())));

	context.close();
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:13,代碼來源:ContentRestAutoConfigurationTests.java

示例12: initDB

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@BeforeClass
public static void initDB() throws SQLException, IOException {
    @SuppressWarnings("resource")
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(DBHikaricpH2Config.class);
    context.register(MybatisConfigMetaObjOptLockConfig.class);
    context.refresh();
    DataSource ds = (DataSource) context.getBean("dataSource");
    try (Connection conn = ds.getConnection()) {
        initData(conn);
    }
}
 
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:13,代碼來源:H2HikaricpTest.java

示例13: init

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@BeforeClass
public static void init() throws SQLException, IOException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ServiceConfig.class);
    context.refresh();
    DataSource ds = (DataSource) context.getBean("dataSource");
    try (Connection conn = ds.getConnection()) {
        initData(conn);
    }
}
 
開發者ID:baomidou,項目名稱:mybatis-plus,代碼行數:11,代碼來源:H2LogicDeleteTest.java

示例14: canBeUsedInNonGenericApplicationContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
@Test
public void canBeUsedInNonGenericApplicationContext() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(Config.class);
	new AutoConfigurationReportLoggingInitializer().initialize(context);
	context.refresh();
	assertThat(context.getBean(ConditionEvaluationReport.class)).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:AutoConfigurationReportLoggingInitializerTests.java

示例15: loadContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入方法依賴的package包/類
/**
 * Load a Spring {@link WebApplicationContext} from the supplied
 * {@link MergedContextConfiguration}.
 * <p/>
 * <p>Implementation details:
 * <p/>
 * <ul>
 * <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)}
 * to allow subclasses to validate the supplied configuration before proceeding.</li>
 * <li>Creates a {@link GenericWebApplicationContext} instance.</li>
 * <li>If the supplied {@code MergedContextConfiguration} references a
 * {@linkplain MergedContextConfiguration#getParent() parent configuration},
 * the corresponding {@link MergedContextConfiguration#getParentApplicationContext()
 * ApplicationContext} will be retrieved and
 * {@linkplain GenericWebApplicationContext#setParent(ApplicationContext) set as the parent}
 * for the context created by this method.</li>
 * <li>Delegates to {@link #configureWebResources} to create the
 * {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li>
 * <li>Calls {@link #prepareContext} to allow for customizing the context
 * before bean definitions are loaded.</li>
 * <li>Delegates to {@link #loadBeanDefinitions} to populate the context
 * from the locations or classes in the supplied {@code MergedContextConfiguration}.</li>
 * <li>Delegates to {@link AnnotationConfigUtils} for
 * {@linkplain AnnotationConfigUtils#registerAnnotationConfigProcessors registering}
 * annotation configuration processors.</li>
 * <li>Calls {@link #customizeContext} to allow for customizing the context
 * before it is refreshed.</li>
 * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the
 * context and registers a JVM shutdown hook for it.</li>
 * </ul>
 *
 * @return a new web application context
 * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration)
 * @see GenericWebApplicationContext
 */
@Override
public final AnnotationConfigWebApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
    SingularContextSetup.reset();

    if (!(mergedConfig instanceof WebMergedContextConfiguration)) {
        throw new IllegalArgumentException(String.format(
                "Cannot load WebApplicationContext from non-web merged context configuration %s. "
                        + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig));
    }
    WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig;

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Loading WebApplicationContext for merged context configuration %s.",
                webMergedConfig));
    }

    validateMergedContextConfiguration(webMergedConfig);

    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();

    ApplicationContext parent = mergedConfig.getParentApplicationContext();
    if (parent != null) {
        context.setParent(parent);
    }
    configureWebResources(context, webMergedConfig);
    prepareContext(context, webMergedConfig);
    customizeContext(context, webMergedConfig);
    loadBeanDefinitions(context, webMergedConfig);
    mockRequest();
    context.refresh();
    context.registerShutdownHook();
    return context;
}
 
開發者ID:opensingular,項目名稱:singular-server,代碼行數:69,代碼來源:AbstractSingularContextLoader.java


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