ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); // DataSource dataSource = (DataSource) context.getBean("dataSource"); // ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"}); DataSource dataSource =(DataSource) context.getBean("dataSource"); Connection conn = (Connection) dataSource.getConnection();