本文整理匯總了Java中org.springframework.context.support.FileSystemXmlApplicationContext類的典型用法代碼示例。如果您正苦於以下問題:Java FileSystemXmlApplicationContext類的具體用法?Java FileSystemXmlApplicationContext怎麽用?Java FileSystemXmlApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileSystemXmlApplicationContext類屬於org.springframework.context.support包,在下文中一共展示了FileSystemXmlApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyEmbeddedConfigurationContext
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
@Test
public void verifyEmbeddedConfigurationContext() {
final PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer();
final Properties properties = new Properties();
properties.setProperty("mongodb.host", "ds061954.mongolab.com");
properties.setProperty("mongodb.port", "61954");
properties.setProperty("mongodb.userId", "casuser");
properties.setProperty("mongodb.userPassword", "Mellon");
properties.setProperty("cas.service.registry.mongo.db", "jasigcas");
configurer.setProperties(properties);
final FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
new String[]{"src/main/resources/META-INF/spring/mongo-services-context.xml"}, false);
ctx.getBeanFactoryPostProcessors().add(configurer);
ctx.refresh();
final MongoServiceRegistryDao dao = new MongoServiceRegistryDao();
dao.setMongoTemplate(ctx.getBean("mongoTemplate", MongoTemplate.class));
cleanAll(dao);
assertTrue(dao.load().isEmpty());
saveAndLoad(dao);
}
示例2: main
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("Usage:");
System.err.println("java " + DbToXML.class.getName() + " <context.xml> <output.xml>");
System.exit(1);
}
String contextPath = args[0];
File outputFile = new File(args[1]);
// Create the Spring context
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(contextPath);
DbToXML dbToXML = new DbToXML(context, outputFile);
dbToXML.execute();
// Shutdown the Spring context
context.close();
}
示例3: fileSystemXmlApplicationContext
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
@Test
public void fileSystemXmlApplicationContext() throws IOException {
ClassPathResource xml = new ClassPathResource(XML_PATH);
File tmpFile = File.createTempFile("test", "xml");
FileCopyUtils.copy(xml.getFile(), tmpFile);
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
ConfigurableApplicationContext ctx =
new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false);
ctx.setEnvironment(prodEnv);
ctx.refresh();
assertEnvironmentBeanRegistered(ctx);
assertHasEnvironment(ctx, prodEnv);
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
示例4: main
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
ClassPathResource classPathResource = new ClassPathResource("beans.xml");
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(classPathResource);
Person person = factory.getBean("person",Person.class);
System.out.println(person.getHand());
System.out.println(person.getName());
System.out.println(classPathResource.getURL());
System.out.println(classPathResource.getFile().getAbsolutePath());
String fileUrl = classPathResource.getFile().getAbsolutePath();
ApplicationContext context = new FileSystemXmlApplicationContext("/Users/fahai/soft/project/meta/src/main/resources/beans.xml");
Person person1 = (Person) factory.getBean("person");
// System.out.println(person1.getName());
// DefaultListableBeanFactory
}
示例5: init
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
/**
* Initialize the security manager using the spring security configuration.
*/
public void init(Properties properties) throws SecurityException {
String configLocation = properties.getProperty(SPRING_SECURITY_CONFIG_LOCATION, "security-config.xml");
if (logger.isLoggable(Level.CONFIG)) {
logger.config("spring-security-config-location: " + configLocation + ", absolute path: " + new File(configLocation).getAbsolutePath());
}
/*
* Extract Spring AuthenticationManager definition
*/
applicationContext = new FileSystemXmlApplicationContext(configLocation);
Map<String, AuthenticationManager> beansOfType = applicationContext.getBeansOfType(AuthenticationManager.class);
if (beansOfType.isEmpty()) {
throw new SecurityException("No bean of type '"+AuthenticationManager.class.getName()+"' is defined in " + configLocation);
}
if (beansOfType.size() > 1) {
throw new SecurityException("More than one bean of type '"+AuthenticationManager.class.getName()+"' is defined in " + configLocation);
}
authenticationManager = beansOfType.values().iterator().next();
}
示例6: readConfigFromXmlFile
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
private static ApplicationConfig readConfigFromXmlFile(final String applicationFilePath) throws BeansException {
ApplicationConfig config;
// Convert to URL to workaround the "everything is a relative paths problem"
// see spring documentation 5.7.3 FileSystemResource caveats.
String fileUri = new File(applicationFilePath).toURI().toString();
final FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(fileUri);
try {
//CR: Catch runtime exceptions. convert to AdminException(s)
context.refresh();
config = context.getBean(ApplicationConfig.class);
}
finally {
if (context.isActive()) {
context.close();
}
}
return config;
}
示例7: main
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args) {
if (args.length == 0 || "".equals(args[0])) {
System.out.println(
"You need to specify an order ID and optionally a number of calls, e.g. for order ID 1000: " +
"'client 1000' for a single call per service or 'client 1000 10' for 10 calls each");
}
else {
int orderId = Integer.parseInt(args[0]);
int nrOfCalls = 1;
if (args.length > 1 && !"".equals(args[1])) {
nrOfCalls = Integer.parseInt(args[1]);
}
ListableBeanFactory beanFactory = new FileSystemXmlApplicationContext(CLIENT_CONTEXT_CONFIG_LOCATION);
OrderServiceClient client = new OrderServiceClient(beanFactory);
client.invokeOrderServices(orderId, nrOfCalls);
}
}
示例8: main
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
/**
* The standard main method which is used by JVM to start execution of the Java class.
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// Start Spring context for the Consumer
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext("src/main/resources/SpringBeans.xml");
String total = null;
String host = "localhost";
try {
host = args[0];
total = args[1];
_log.info("-------------------------------------");
_log.info("Active MQ host >>>> "+host);
_log.info("Total messages to send >>>> "+total);
_log.info("-------------------------------------");
// Start the publishing of some messages using regular HTTP POST
sendMessage(host, Integer.valueOf(total));
} catch (Exception e) {
_log.info("------------------------------------------------------------------------------------------------------------------");
_log.info("PAY ATTENTION!!! You must enter the Active MQ host and a number representing the total messages to produce");
_log.info("------------------------------------------------------------------------------------------------------------------");
_log.info("Example: mvn exec:java -Dexec.args=\"localhost 10\"");
System.exit(1);
}
}
示例9: HapporSpringContext
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public HapporSpringContext(final ClassLoader classLoader, String filename) {
this.classLoader = classLoader;
ctx = new FileSystemXmlApplicationContext(filename) {
@Override
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
super.initBeanDefinitionReader(reader);
reader.setBeanClassLoader(classLoader);
setClassLoader(classLoader);
}
};
registerAllBeans();
setServer(ctx.getBean(HapporWebserver.class));
try {
setWebserverHandler(ctx.getBean(WebserverHandler.class));
} catch (NoSuchBeanDefinitionException e) {
logger.warn("has no WebserverHandler");
}
}
示例10: startNodes
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
/**
*
* @throws Exception If failed.
*/
private void startNodes() throws Exception {
AbstractApplicationContext ctxSpring = new FileSystemXmlApplicationContext(springCfgFileOutTmplName + 0);
// We have to deploy Services for service is available at the bean creation time for other nodes.
Ignite ignite = (Ignite)ctxSpring.getBean("testIgnite");
ignite.services().deployMultiple(SERVICE_NAME, new DummyServiceImpl(), NODES, 1);
// Add other nodes.
for (int i = 1; i < NODES; ++i)
new FileSystemXmlApplicationContext(springCfgFileOutTmplName + i);
assertEquals(NODES, G.allGrids().size());
assertEquals(NODES, ignite.cluster().nodes().size());
}
示例11: main
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public static void main(String[] args) {
FileSystemXmlApplicationContext applicationContext=new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
// MemcachedCache cache=(MemcachedCache) applicationContext.getBean("memClient");
// IMemcachedCache cc=cache.getCache();
//cache.put("1111", object)''
// System.out.println(cache.get("emp1"));
AService a=(AService) applicationContext.getBean("aimpl");
// AService B=(AService) applicationContext.getBean("bimpl");
System.out.println((String)a.testaop("test2"));
// B.before();
// System.out.println(emp.getCompanyName());
}
示例12: WebServiceProxy
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
/**
* Initializes the web service proxy based on the handle to the File.
*
* @param configurationFile
* The File handle to the configuration file.
*/
public WebServiceProxy(File configurationFile) {
String path = configurationFile.getAbsolutePath();
FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(
"file:" + path);
try {
this.webProxyConfiguration = applicationContext
.getBean(WebProxyConfiguration.class);
Map<String, ModuleConfiguration> moduleConfigurations = applicationContext
.getBeansOfType(ModuleConfiguration.class);
initializeModules(moduleConfigurations.values());
} finally {
applicationContext.close();
}
}
示例13: testInjection
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
@Test
public void testInjection(){
System.setProperty("log.path", ProjectConfig.getProperty("log.path"));
@SuppressWarnings("resource")
ApplicationContext context = new FileSystemXmlApplicationContext("src/main/webapp/WEB-INF/spring/applicationContext.xml");
SysSettingService sysSettingService = (SysSettingService)context.getBean("sysSettingService");
// SysSetting sysSetting = new SysSetting();
//
// sysSetting.setCreateperson(1);
// sysSetting.setEditperson(1);
// sysSetting.setCreatetime(new Date());
// sysSetting.setEdittime(new Date());
// sysSetting.setPropKey("係統安全級別");
// sysSetting.setPropValue("高級");
// sysSetting.setRemark("在此安全級別下,任何未授權訪問都會被拒絕。");
//
// sysSettingService.save(sysSetting);
System.err.println(Util.getJsonObject(sysSettingService.selectAll()));
}
示例14: fileSystemXmlApplicationContext
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
@Test
public void fileSystemXmlApplicationContext() throws IOException {
ClassPathResource xml = new ClassPathResource(XML_PATH);
File tmpFile = File.createTempFile("test", "xml");
FileCopyUtils.copy(xml.getFile(), tmpFile);
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
ConfigurableApplicationContext ctx =
new FileSystemXmlApplicationContext(new String[] { "file:"+tmpFile.getPath() }, false);
ctx.setEnvironment(prodEnv);
ctx.refresh();
assertEnvironmentBeanRegistered(ctx);
assertHasEnvironment(ctx, prodEnv);
assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
示例15: loadCxt
import org.springframework.context.support.FileSystemXmlApplicationContext; //導入依賴的package包/類
public static ApplicationContext loadCxt(String path)
{
try
{
return new ClassPathXmlApplicationContext(path);
}
catch(Throwable t)
{
try
{
if(t.getCause() instanceof FileNotFoundException)
return new FileSystemXmlApplicationContext(path);
}
catch(Throwable t1)
{
lg.error("loading spring context fail",t1);
return null;
}
lg.error("loading spring context fail",t);
}
return null;
}