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