Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#setConfigLocation()

The following examples show how to use org.springframework.context.support.ClassPathXmlApplicationContext#setConfigLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationDtoPostProcessorLayerTreeTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testLayerTreeCheck() throws Exception {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/testdata/beanContext.xml " +
				"/org/geomajas/testdata/layerBeans.xml " +
				"/org/geomajas/internal/configuration/layerTreeInvalid.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		Assert.assertTrue(bce.getCause().getMessage().startsWith(
				"A LayerTreeNodeInfo object can only reference layers which are part of the map, layer "));
	}
}
 
Example 2
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testUserStyle() {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
	context.setId("test");
	context.setDisplayName("test");
	context.setConfigLocation(
			"/org/geomajas/spring/geomajasContext.xml "+
			"/org/geomajas/internal/configuration/layerDefaultStyle.xml ");
	context.refresh();
	VectorLayer layerDefaultStyle = (VectorLayer)context.getBean("layerDefaultStyle");
	List<NamedStyleInfo> styles = layerDefaultStyle.getLayerInfo().getNamedStyleInfos();
	Assert.assertEquals(1, styles.size());
	NamedStyleInfo defaultStyle = styles.get(0);
	UserStyleInfo userStyle = defaultStyle.getUserStyle();
	List<RuleInfo> rules = userStyle.getFeatureTypeStyleList().get(0).getRuleList();
	Assert.assertEquals(1, rules.size());
	Assert.assertEquals(null, rules.get(0).getName());
}
 
Example 3
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testDefaultStyle() {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
	context.setId("test");
	context.setDisplayName("test");
	context.setConfigLocation(
			"/org/geomajas/spring/geomajasContext.xml "+
			"/org/geomajas/internal/configuration/layerDefaultStyle.xml ");
	context.refresh();
	VectorLayer layerDefaultStyle = (VectorLayer)context.getBean("layerDefaultStyle");
	List<NamedStyleInfo> styles = layerDefaultStyle.getLayerInfo().getNamedStyleInfos();
	Assert.assertEquals(1, styles.size());
	NamedStyleInfo defaultStyle = styles.get(0);
	Assert.assertEquals(NamedStyleInfo.DEFAULT_NAME, defaultStyle.getName());
	Assert.assertEquals(LabelStyleInfo.ATTRIBUTE_NAME_ID, defaultStyle.getLabelStyle().getLabelAttributeName());
}
 
Example 4
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testDuplicateAttributeInManyToOne() {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/internal/configuration/layerBeansDuplicateAttrManyToOne.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Duplicate attribute name stringAttr in layer beans, path /manyToOneAttr.");
	}
}
 
Example 5
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testDuplicateAttributeInOneToMany() {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/internal/configuration/layerBeansDuplicateAttrOneToMany.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Duplicate attribute name stringAttr in layer beans, path /oneToManyAttr.");
	}
}
 
Example 6
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testDuplicateAttribute() {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/internal/configuration/layerBeansDuplicateAttribute.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Duplicate attribute name stringAttr in layer beans, path .");
	}
}
 
Example 7
Source File: ConfigurationDtoPostProcessorVectorLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testAttributeInvalidNameCheck() {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/testdata/beanContext.xml " +
				"/org/geomajas/testdata/layerBeans.xml " +
				"/org/geomajas/internal/configuration/layerBeansInvalid.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Invalid attribute name manyToOne.stringAttr in layer beans.");
	}
}
 
Example 8
Source File: ConfigurationDtoPostProcessorRasterLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testNullTileHeight() throws Exception {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/internal/configuration/RasterLayerZeroTileHeight.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Layer layerOsm is not correctly configured: tileHeight should not be zero.");
	}
}
 
Example 9
Source File: ConfigurationDtoPostProcessorRasterLayerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testNullTileWidth() throws Exception {
	try {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
		context.setId("test");
		context.setDisplayName("test");
		context.setConfigLocation(
				"/org/geomajas/spring/geomajasContext.xml " +
				"/org/geomajas/internal/configuration/RasterLayerZeroTileWidth.xml " +
				"");
		context.refresh();
		Assert.fail("Context initialization should have failed.");
	} catch (BeanCreationException bce) {
		assertThat(bce.getCause().getCause().getMessage()).startsWith(
				"Layer layerOsm is not correctly configured: tileWidth should not be zero.");
	}
}
 
Example 10
Source File: UserCreateTools.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles("production");
    ctx.setConfigLocation("applicationContext.xml");
    ctx.refresh();

    userDao = (UserDao) ctx.getBean("userDaoImpl");

    /**
     * 生成测试用户 SQL
     */
    UserCreateCommon.generateCreateTestUserSQL(userDao);

    /**
     * 生成指定用户 SQL
     */
    UserCreateCommon.generateCreateSpecifyUserSQL(userDao, "msoa", "msoaSH", RoleEnum.ADMIN, "");

    System.exit(1);
}
 
Example 11
Source File: UserCreateTools.java    From disconf with Apache License 2.0 6 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext();
    ctx.getEnvironment().setActiveProfiles("production");
    ctx.setConfigLocation("applicationContext.xml");
    ctx.refresh();

    userDao = (UserDao) ctx.getBean("userDaoImpl");

    /**
     * 生成测试用户 SQL
     */
    UserCreateCommon.generateCreateTestUserSQL(userDao);

    /**
     * 生成指定用户 SQL
     */
    UserCreateCommon.generateCreateSpecifyUserSQL(userDao, "msoa", "msoaSH", RoleEnum.ADMIN, "");

    System.exit(1);
}
 
Example 12
Source File: QueryLogicFactoryBeanTest.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IllegalArgumentException, IllegalAccessException {
    System.setProperty(NpeUtils.NPE_OU_PROPERTY, "iamnotaperson");
    System.setProperty("dw.metadatahelper.all.auths", "A,B,C,D");
    Logger.getLogger(ClassPathXmlApplicationContext.class).setLevel(Level.OFF);
    Logger.getLogger(XmlBeanDefinitionReader.class).setLevel(Level.OFF);
    Logger.getLogger(DefaultListableBeanFactory.class).setLevel(Level.OFF);
    ClassPathXmlApplicationContext queryFactory = new ClassPathXmlApplicationContext();
    queryFactory.setConfigLocation("TestQueryLogicFactory.xml");
    queryFactory.refresh();
    factoryConfig = queryFactory.getBean(QueryLogicFactoryConfiguration.class.getSimpleName(), QueryLogicFactoryConfiguration.class);
    
    Whitebox.setInternalState(bean, QueryLogicFactoryConfiguration.class, factoryConfig);
    Whitebox.setInternalState(bean, ClassPathXmlApplicationContext.class, queryFactory);
    
    ctx = createMock(EJBContext.class);
    logic = createMockBuilder(BaseQueryLogic.class).addMockedMethods("setLogicName", "getMaxPageSize", "getPageByteTrigger").createMock();
    DatawaveUser user = new DatawaveUser(SubjectIssuerDNPair.of("CN=Poe Edgar Allan eapoe, OU=acme", "<CN=ca, OU=acme>"), UserType.USER, null, null, null,
                    0L);
    principal = new DatawavePrincipal(Collections.singletonList(user));
}
 
Example 13
Source File: DispatcherWebscriptMockitoTest.java    From alfresco-mvc with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public void beforeAll() throws Exception {
	MockitoAnnotations.initMocks(this);

	webScript.setServletContext(new MockServletContext());
	webScript.setContextConfigLocation("test-webscriptdispatcher-context.xml");

	ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext();
	applicationContext.setConfigLocation("web-context-test.xml");
	applicationContext.refresh();
	webScript.setApplicationContext(applicationContext);
	webScript.onApplicationEvent(new ContextRefreshedEvent(applicationContext));

	mockWebscript = MockWebscriptBuilder.singleWebscript(webScript);
}
 
Example 14
Source File: DemoServiceConsumerXmlBootstrap.java    From dubbo-registry-nacos with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.setConfigLocation("/META-INF/spring/dubbo-consumer-context.xml");
    context.refresh();
    System.out.println("DemoService consumer (XML) is starting...");
    DemoService demoService = context.getBean("demoService", DemoService.class);
    for (int i = 0; i < 10; i++) {
        System.out.println(demoService.sayName("小马哥(mercyblitz)"));
    }
    System.in.read();
    context.close();
}
 
Example 15
Source File: GeotoolsInitializerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testLogging() {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
	context.setId("test");
	context.setDisplayName("test");
	context.setConfigLocation("/org/geomajas/spring/geomajasContext.xml ");
	context.refresh();
	Assert.assertSame(Logging.GEOTOOLS.getLoggerFactory(), Slf4jLoggerFactory.getInstance());
}
 
Example 16
Source File: KFSTestStartup.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void initializeKfsTestContext() {
    long startInit = System.currentTimeMillis();
    LOG.info("Initializing Kuali Rice Application...");

    String bootstrapSpringBeans = "classpath:kfs-startup-test.xml";

    Properties baseProps = new Properties();
    baseProps.putAll(System.getProperties());
    JAXBConfigImpl config = new JAXBConfigImpl(baseProps);
    ConfigContext.init(config);

    context = new ClassPathXmlApplicationContext();
    context.setConfigLocation(bootstrapSpringBeans);
    try {
        context.refresh();
    } catch (RuntimeException e) {
        LOG.error("problem during context.refresh()", e);

        throw e;
    }

    context.start();
    long endInit = System.currentTimeMillis();
    LOG.info("...Kuali Rice Application successfully initialized, startup took " + (endInit - startInit) + " ms.");

    SpringContext.finishInitializationAfterRiceStartup();
}
 
Example 17
Source File: XmlConfigBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // 构建 XML 配置驱动 Spring 上下文
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    // 设置 XML 配置文件的位置
    context.setConfigLocation("classpath:/META-INF/spring/context.xml");
    // 启动上下文
    context.refresh();
    // 获取名称为 "user" Bean 对象
    User user = context.getBean("user", User.class);
    // 输出用户名称:"小马哥"
    System.out.printf("user.getName() = %s \n",user.getName());
    // 关闭 Spring 上下文
    context.close();
}
 
Example 18
Source File: DerivedComponentAnnotationBootstrap.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    // 构建 XML 配置驱动 Spring 上下文
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    // 设置 XML 配置文件的位置
    context.setConfigLocation("classpath:/META-INF/spring/context.xml");
    // 启动上下文
    context.refresh();
    // 获取名称为 "chineseNameRepository" Bean 对象
    NameRepository nameRepository = (NameRepository) context.getBean("chineseNameRepository");
    // 输出用户名称:[张三, 李四, 小马哥]
    System.out.printf("nameRepository.findAll() = %s \n", nameRepository.findAll());
}
 
Example 19
Source File: DemoServiceProviderXmlBootstrap.java    From dubbo-registry-nacos with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    context.setConfigLocation("/META-INF/spring/dubbo-provider-context.xml");
    context.refresh();
    System.out.println("DemoService provider (XML) is starting...");
    System.in.read();
}
 
Example 20
Source File: MaskedValueFilterFactory.java    From datawave with Apache License 2.0 4 votes vote down vote up
private static MaskedValueFilterInterface createInstance() {
    
    ClassLoader thisClassLoader = MaskedValueFilterFactory.class.getClassLoader();
    if (log.isDebugEnabled()) {
        if (thisClassLoader instanceof VFSClassLoader) {
            log.debug("thisClassLoader is a VFSClassLoader with resources:" + Arrays.toString(((VFSClassLoader) thisClassLoader).getFileObjects()));
        } else {
            log.debug("thisClassLoader is a :" + thisClassLoader.getClass());
        }
    }
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
    MaskedValueFilterInterface instance = null;
    try {
        // To prevent failure when this is run on the tservers:
        // The VFS ClassLoader has been created and has been made the current thread's context classloader, but its resource paths are empty at this time.
        // The spring ApplicationContext will prefer the current thread's context classloader, so the spring context would fail to find
        // any classes or context files to load.
        // Instead, set the classloader on the ApplicationContext to be the one that is loading this class.
        // It is a VFSClassLoader that has the accumulo lib/ext jars set as its resources.
        // After setting the classloader, then set the config locations and refresh the context.
        context.setClassLoader(thisClassLoader);
        context.setConfigLocation("classpath:/MaskingFilterContext.xml");
        context.refresh();
        instance = context.getBean("maskedValueFilter", MaskedValueFilterInterface.class);
    } catch (Throwable t) {
        // got here because the VFSClassLoader on the tservers does not implement findResources
        // none of the spring wiring will work, so fall back to reflection:
        log.warn("got {}", t);
        String className = System.getProperty(MASKED_VALUE_FILTER_CLASSNAME);
        log.debug("{}{}", MASKED_VALUE_FILTER_CLASSNAME, className);
        if (className != null) {
            try {
                instance = (MaskedValueFilterInterface) Class.forName(className).newInstance();
            } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
                log.warn("unable to create MaskedValueFilterInterface", e);
                throw new RuntimeException("Could not create MaskedValueFilterInterface object");
            }
        } else {
            log.warn("className was null, unable to create " + MASKED_VALUE_FILTER_CLASSNAME);
        }
        log.debug("{}: {}", MASKED_VALUE_FILTER_CLASSNAME, (null != instance ? instance : "null"));
    } finally {
        context.close();
    }
    return instance;
}