本文整理了Java中org.springframework.context.support.ClassPathXmlApplicationContext.refresh()
方法的一些代码示例,展示了ClassPathXmlApplicationContext.refresh()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassPathXmlApplicationContext.refresh()
方法的具体详情如下:
包路径:org.springframework.context.support.ClassPathXmlApplicationContext
类名称:ClassPathXmlApplicationContext
方法名:refresh
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new ClassPathXmlApplicationContext with the given parent,
* loading the definitions from the given XML files and automatically
* refreshing the context.
* @param paths array of relative (or absolute) paths within the class path
* @param clazz the class to load resources with (basis for the given paths)
* @param parent the parent context
* @throws BeansException if context creation failed
* @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
* @see org.springframework.context.support.GenericApplicationContext
* @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
*/
public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, @Nullable ApplicationContext parent)
throws BeansException {
super(parent);
Assert.notNull(paths, "Path array must not be null");
Assert.notNull(clazz, "Class argument must not be null");
this.configResources = new Resource[paths.length];
for (int i = 0; i < paths.length; i++) {
this.configResources[i] = new ClassPathResource(paths[i], clazz);
}
refresh();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new ClassPathXmlApplicationContext with the given parent,
* loading the definitions from the given XML files.
* @param configLocations array of resource locations
* @param refresh whether to automatically refresh the context,
* loading all bean definitions and creating all singletons.
* Alternatively, call refresh manually after further configuring the context.
* @param parent the parent context
* @throws BeansException if context creation failed
* @see #refresh()
*/
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new ClassPathXmlApplicationContext with the given parent,
* loading the definitions from the given XML files and automatically
* refreshing the context.
* @param paths array of relative (or absolute) paths within the class path
* @param clazz the class to load resources with (basis for the given paths)
* @param parent the parent context
* @throws BeansException if context creation failed
* @see org.springframework.core.io.ClassPathResource#ClassPathResource(String, Class)
* @see org.springframework.context.support.GenericApplicationContext
* @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
*/
public ClassPathXmlApplicationContext(String[] paths, Class<?> clazz, @Nullable ApplicationContext parent)
throws BeansException {
super(parent);
Assert.notNull(paths, "Path array must not be null");
Assert.notNull(clazz, "Class argument must not be null");
this.configResources = new Resource[paths.length];
for (int i = 0; i < paths.length; i++) {
this.configResources[i] = new ClassPathResource(paths[i], clazz);
}
refresh();
}
代码示例来源:origin: org.springframework/spring-context
/**
* Create a new ClassPathXmlApplicationContext with the given parent,
* loading the definitions from the given XML files.
* @param configLocations array of resource locations
* @param refresh whether to automatically refresh the context,
* loading all bean definitions and creating all singletons.
* Alternatively, call refresh manually after further configuring the context.
* @param parent the parent context
* @throws BeansException if context creation failed
* @see #refresh()
*/
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {
super(parent);
setConfigLocations(configLocations);
if (refresh) {
refresh();
}
}
代码示例来源:origin: geoserver/geoserver
@Before
public void setUp() throws Exception {
File f = new File("target/foo.properties");
if (f.exists()) f.delete();
ctx =
new ClassPathXmlApplicationContext(
"GeoServerPropertyConfigurerTest-applicationContext.xml", getClass());
ctx.refresh();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void refresh() throws BeansException {
try {
super.refresh();
}
catch (BeanCreationException ex) {
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) getBeanFactory();
assertEquals(0, factory.getSingletonCount());
throw ex;
}
}
};
代码示例来源:origin: geoserver/geoserver
@Before
public void setUp() throws Exception {
ctx =
new ClassPathXmlApplicationContext(
"GeoServerDataDirectoryTest-applicationContext.xml", getClass());
ctx.refresh();
dataDir = new GeoServerDataDirectory(Files.createTempDirectory("data").toFile());
dataDir.root().deleteOnExit();
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testAllowBeanOverride() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setConfigLocation("org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml");
applicationContext.refresh();
}
代码示例来源:origin: geoserver/geoserver
@Test
public void testUserSpecified() throws Exception {
Properties p = new Properties();
p.put("prop1", "foobar");
p.put("prop2", "barfoo");
FileOutputStream out = new FileOutputStream("target/foo.properties");
p.store(out, "");
out.flush();
out.close();
ctx.refresh();
Foo f = (Foo) ctx.getBean("myBean");
assertEquals("foobar", f.getBar());
assertEquals("barfoo", f.getBaz());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testAllowBeanOverrideFalse() {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setAllowBeanDefinitionOverriding(false);
applicationContext.setConfigLocation("org/springframework/batch/core/configuration/xml/BeanDefinitionOverrideTests-context.xml");
applicationContext.refresh();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testAliasWithPlaceholder() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
FQ_CONTEXT_B, FQ_ALIASED_CONTEXT_C, FQ_CONTEXT_A);
assertTrue(ctx.containsBean("service"));
assertTrue(ctx.containsBean("logicOne"));
assertTrue(ctx.containsBean("logicTwo"));
ctx.refresh();
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void registerDataValueProcessorOnlyIfNotRegistered() throws Exception {
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext()) {
context.setAllowBeanDefinitionOverriding(false);
context.setConfigLocation(this.xml("RegisterDataValueProcessorOnyIfNotRegistered"));
context.refresh();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextWithInvalidValueType() throws IOException {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {INVALID_VALUE_TYPE_CONTEXT}, false);
try {
context.refresh();
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
assertTrue(ex.contains(TypeMismatchException.class));
assertTrue(ex.toString().contains("someMessageSource"));
assertTrue(ex.toString().contains("useCodeAsDefaultMessage"));
checkExceptionFromInvalidValueType(ex);
checkExceptionFromInvalidValueType(new ExceptionInInitializerError(ex));
assertFalse(context.isActive());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testMultipleConfigLocations() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
FQ_CONTEXT_B, FQ_CONTEXT_C, FQ_CONTEXT_A);
assertTrue(ctx.containsBean("service"));
assertTrue(ctx.containsBean("logicOne"));
assertTrue(ctx.containsBean("logicTwo"));
// re-refresh (after construction refresh)
Service service = (Service) ctx.getBean("service");
ctx.refresh();
assertTrue(service.isProperlyDestroyed());
// regular close call
service = (Service) ctx.getBean("service");
ctx.close();
assertTrue(service.isProperlyDestroyed());
// re-activating and re-closing the context (SPR-13425)
ctx.refresh();
service = (Service) ctx.getBean("service");
ctx.close();
assertTrue(service.isProperlyDestroyed());
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRemoteChunkingMasterIdAttrAssert() throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setValidating(false);
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingIdAttrTests.xml");
try {
applicationContext.refresh();
fail();
} catch (BeanDefinitionStoreException e) {
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(),
"The id attribute must be specified".equals(iae.getMessage()));
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRemoteChunkingSlaveOutputChannelAttrAssert() throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setValidating(false);
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingOutputChannelAttrTests.xml");
try {
applicationContext.refresh();
fail();
} catch (BeanDefinitionStoreException e) {
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
assertTrue("Expected: " + "The output-channel attribute must be specified" + " but got: " + iae.getMessage(),
"The output-channel attribute must be specified".equals(iae.getMessage()));
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRemoteChunkingSlaveIdAttrAssert() throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setValidating(false);
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingIdAttrTests.xml");
try {
applicationContext.refresh();
fail();
} catch (BeanDefinitionStoreException e) {
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
assertTrue("Expected: " + "The id attribute must be specified" + " but got: " + iae.getMessage(),
"The id attribute must be specified".equals(iae.getMessage()));
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRemoteChunkingSlaveInputChannelAttrAssert() throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setValidating(false);
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingSlaveParserMissingInputChannelAttrTests.xml");
try {
applicationContext.refresh();
fail();
} catch (BeanDefinitionStoreException e) {
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
assertTrue("Expected: " + "The input-channel attribute must be specified" + " but got: " + iae.getMessage(),
"The input-channel attribute must be specified".equals(iae.getMessage()));
}
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testRemoteChunkingMasterReplyChannelAttrAssert() throws Exception {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
applicationContext.setValidating(false);
applicationContext.setConfigLocation("/org/springframework/batch/integration/config/xml/RemoteChunkingMasterParserMissingReplyChannelAttrTests.xml");
try {
applicationContext.refresh();
fail();
} catch (BeanDefinitionStoreException e) {
assertTrue("Nested exception must be of type IllegalArgumentException", e.getCause() instanceof IllegalArgumentException);
IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
assertTrue("Expected: " + "The reply-channel attribute must be specified" + " but got: " + iae.getMessage(),
"The reply-channel attribute must be specified".equals(iae.getMessage()));
}
}
代码示例来源:origin: spring-projects/spring-framework
public void handlerMappingXmlConfig() throws Exception {
ClassPathXmlApplicationContext wac = new ClassPathXmlApplicationContext("map.xml", getClass());
wac.refresh();
内容来源于网络,如有侵权,请联系作者删除!