Search in sources :

Example 6 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project sharding-jdbc by dangdangdotcom.

the class SpringNamespaceWithMasterSlaveMain method main.

// CHECKSTYLE:OFF
public static void main(final String[] args) throws SQLException {
    // CHECKSTYLE:ON
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/applicationContextWithMasterSlave.xml");
    OrderService orderService = applicationContext.getBean(OrderService.class);
    orderService.insert();
    orderService.select();
    orderService.delete();
    orderService.select();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) OrderService(com.dangdang.ddframe.rdb.sharding.example.config.spring.masterslave.service.OrderService)

Example 7 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project cucumber-jvm by cucumber.

the class CucumberTestContextManager method createFallbackContext.

@SuppressWarnings("resource")
private ConfigurableListableBeanFactory createFallbackContext() {
    ConfigurableApplicationContext applicationContext;
    if (getClass().getClassLoader().getResource("cucumber.xml") != null) {
        applicationContext = new ClassPathXmlApplicationContext("cucumber.xml");
    } else {
        applicationContext = new GenericApplicationContext();
    }
    applicationContext.registerShutdownHook();
    ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    beanFactory.registerScope(GlueCodeScope.NAME, new GlueCodeScope());
    for (Class<?> stepClass : stepClasses) {
        registerStepClassBeanDefinition(beanFactory, stepClass);
    }
    return beanFactory;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 8 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project OpenMEAP by OpenMEAP.

the class ModelTestUtils method getPersistenceBean.

public static synchronized Object getPersistenceBean(String name) {
    if (persistenceBeans == null) {
        System.setProperty("hibernate.show_sql", "true");
        System.setProperty("hibernate.hbm2ddl.auto", "update");
        System.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLite3Dialect");
        System.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC");
        System.setProperty("hibernate.connection.url", "jdbc:sqlite:" + OPENMEAP_TEST_DB);
        persistenceBeans = new ClassPathXmlApplicationContext(new String[] { "/META-INF/persistenceContext.xml", "/META-INF/test/persistenceContext.xml" });
    }
    return persistenceBeans.getBean(name);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 9 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project OpenMEAP by OpenMEAP.

the class ModelTestUtils method main.

/**
	 * I used this mainly to generate the DDL.
	 * @param argv
	 */
public static void main(String[] argv) {
    //getPersistenceBean("modelManager");
    if (persistenceBeans == null) {
        System.setProperty("hibernate.show_sql", "true");
        System.setProperty("hibernate.hbm2ddl.auto", "update");
        System.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        System.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        System.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/openmeap");
        System.setProperty("hibernate.connection.username", "openmeap");
        System.setProperty("hibernate.connection.password", "password");
        persistenceBeans = new ClassPathXmlApplicationContext(new String[] { "/META-INF/persistenceContext.xml", "/META-INF/test/persistenceContext.xml" });
    }
    createModel(null);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 10 with ClassPathXmlApplicationContext

use of org.springframework.context.support.ClassPathXmlApplicationContext in project druid by alibaba.

the class SpringMybatisFilterTest method test_spring.

public void test_spring() throws Exception {
    Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/alibaba/druid/pool/mybatis/spring-config-mybatis.xml");
    DataSource dataSource = (DataSource) context.getBean("dataSource");
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE sequence_seed (value INTEGER, name VARCHAR(50))");
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE t_User (id BIGINT, name VARCHAR(50))");
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        conn.setAutoCommit(false);
        Statement stmt = conn.createStatement();
        stmt.execute("insert into sequence_seed (value ,name) values (0, 'druid-spring-test')");
        stmt.close();
        conn.commit();
        conn.close();
    }
    UserMapper userMapper = (UserMapper) context.getBean("userMapper");
    {
        User user = new User();
        user.setName("xx");
        userMapper.addUser(user);
    }
    {
        userMapper.errorSelect(1);
    }
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("DROP TABLE sequence_seed");
        stmt.close();
        conn.close();
    }
    {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        stmt.execute("DROP TABLE t_User");
        stmt.close();
        conn.close();
    }
    context.close();
    Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
}
Also used : User(com.alibaba.druid.spring.User) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Statement(java.sql.Statement) Connection(java.sql.Connection) DataSource(javax.sql.DataSource)

Aggregations

ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)480 Test (org.junit.Test)212 ApplicationContext (org.springframework.context.ApplicationContext)149 Before (org.junit.Before)47 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)33 ITestBean (org.springframework.tests.sample.beans.ITestBean)30 Messenger (org.springframework.scripting.Messenger)29 CamelContext (org.apache.camel.CamelContext)25 Refreshable (org.springframework.aop.target.dynamic.Refreshable)23 AbstractXmlApplicationContext (org.springframework.context.support.AbstractXmlApplicationContext)22 DataSource (javax.sql.DataSource)17 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)16 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)13 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)13 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 DemoService (com.alibaba.dubbo.config.spring.api.DemoService)11 ProducerTemplate (org.apache.camel.ProducerTemplate)10 File (java.io.File)9 URL (com.alibaba.dubbo.common.URL)8 Service (org.apache.camel.Service)8