Example usage for org.springframework.context.support ClassPathXmlApplicationContext close

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext close

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext close.

Prototype

@Override
public void close() 

Source Link

Document

Close this application context, destroying all beans in its bean factory.

Usage

From source file:com.brienwheeler.apps.schematool.SchemaToolBeanTest.java

@Test
public void testSchemaExportLocationValidatingPUP() {
    PropertiesTestUtils.clearAllTestSystemProperties();

    System.setProperty("com.brienwheeler.apps.schematool.schemaTool.mode", "CLEAN");
    System.setProperty("com.brienwheeler.apps.schematool.schemaTool.exec", "false");
    System.setProperty("com.brienwheeler.apps.schematool.schemaTool.closeContextOnDone", "false");
    System.setProperty("com.brienwheeler.apps.schematool.schemaTool.emfContextLocation",
            CONTEXT_LOCATION_LVPUP);//from w  w w.  j a  v a 2s .c o m
    System.setProperty("com.brienwheeler.apps.schematool.schemaTool.emfPersistenceLocationsPropValue",
            "classpath:com/brienwheeler/lib/db/persistence.xml,"
                    + "classpath:com/brienwheeler/lib/db/persistence-test.xml");

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONTEXT_LOCATION_SCHEMATOOL);
    context.close();
}

From source file:edu.mayo.cts2.uriresolver.logging.URILogger.java

public URILogger(Class<?> classname) {
    logger = Logger.getLogger(classname);

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    debugging = (LogDetails) context.getBean("logDetails");
    context.close();
}

From source file:sipackage.SpringIntegrationTest.java

@Test
public void testSpringIntegrationContextStartup() throws Exception {

    ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/spring-integration-context.xml", SpringIntegrationTest.class);
    Thread.sleep(4000);//  w w w .ja v  a2  s. c  om
    classPathXmlApplicationContext.close();

}

From source file:com.chevres.rss.restapi.controller.RegisterController.java

@CrossOrigin
@RequestMapping(path = "/register", method = RequestMethod.POST)
@ResponseBody//from ww  w. ja  v a  2  s . com
public HttpEntity<String> register(@RequestBody User user, BindingResult bindingResult) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    userValidator.validate(user, bindingResult);

    if (bindingResult.hasErrors()) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST);
    }

    UserDAO userDAO = context.getBean(UserDAO.class);

    if (userDAO.doesExist(user.getUsername())) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("already_exist"), HttpStatus.BAD_REQUEST);
    }

    PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
    String hashedPassword = passwordEncoder.encode(user.getPassword());
    user.setPassword(hashedPassword);
    user.setType(User.USER_TYPE_LABEL);
    userDAO.create(user);

    context.close();

    return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK);
}

From source file:org.wgrus.ServletConfigurationTests.java

@Test
public void testContext() throws Exception {

    ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("classpath:/root-context.xml");

    try {// ww w .  ja  v a  2s .com

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "classpath:/servlet-context.xml" }, parent);

        try {

        } finally {
            context.close();
        }

    } finally {

        parent.close();

    }

}

From source file:org.aksw.gerbil.web.config.DatabaseConfig.java

/**
 * @return the database bean// w ww  .  j av  a2 s.  c  o m
 */
@Bean
public ExperimentDAO experimentDAO() {
    LOGGER.debug("Setting up database.");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/spring/database/database-context.xml");
    ExperimentDAO database = context.getBean(ExperimentDAO.class);
    database.initialize();
    context.close();
    return database;
}

From source file:com.chevres.rss.restapi.controller.LoginController.java

@CrossOrigin
@RequestMapping(path = "/login", method = RequestMethod.POST)
@ResponseBody//from w ww .  j  a  va 2  s.  c o  m
public ResponseEntity<String> login(@RequestBody User user, BindingResult bindingResult) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    userValidator.validate(user, bindingResult);

    if (bindingResult.hasErrors()) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST);
    }

    UserDAO userDAO = context.getBean(UserDAO.class);
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    User foundUser = userDAO.findByUsernameAndPassword(user.getUsername(), user.getPassword());
    if (foundUser == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_credentials"), HttpStatus.BAD_REQUEST);
    }

    TokenGenerator tg = new TokenGenerator();
    Date date = new Date();
    Timestamp timestamp = new Timestamp(date.getTime());

    UserAuth userAuth = new UserAuth();
    userAuth.setIdUser(foundUser.getId());
    userAuth.setToken(tg.getToken());
    userAuth.setCreateDate(timestamp);
    userAuthDAO.create(userAuth);

    context.close();

    return new ResponseEntity(new SuccessLoginResponse(userAuth.getToken()), HttpStatus.OK);
}

From source file:com.enterra.batch.admin.sample.BootstrapTests.java

@Test
public void testBootstrapConfiguration() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath*:/META-INF/spring/batch/bootstrap/**/*.xml");
    assertTrue(context.containsBean("jobRepository"));
    context.close();
}

From source file:nats.client.spring.NatsFactoryBeanTest.java

@Test
public void natsFactory() throws Exception {
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("natsFactoryContext.xml");
    try {/*from ww w . ja  v a 2s.  com*/
        final Nats nats = context.getBean(Nats.class);
        Assert.assertNotNull(nats);
    } finally {
        context.close();
    }
}

From source file:com.enterra.batch.admin.sample.BootstrapTests.java

@Test
public void testWebappRootConfiguration() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:/org/springframework/batch/admin/web/resources/webapp-config.xml");
    assertTrue(context.containsBean("jobRepository"));
    context.close();
}