Allow <jdbc:embedded-database> to be declared w/o id

This commit modifies EmbeddedDatabaseBeanDefinitionParser so that the
<jdbc:embedded-database> XML namespace element can be declared as an
anonymous bean (i.e., without an explicit ID).

Issue: SPR-12834
This commit is contained in:
Sam Brannen
2015-03-20 15:48:04 +01:00
parent 85e4b24abb
commit 7e2f12cf9f
3 changed files with 47 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,11 @@ public class JdbcNamespaceIntegrationTests {
assertCorrectSetup("jdbc-config.xml", "derbyDataSource");
}
@Test
public void createWithAnonymousDataSource() throws Exception {
assertCorrectSetupAndCloseContextForSingleDataSource("jdbc-config-anonymous-datasource.xml", 1);
}
@Test
public void createWithResourcePattern() throws Exception {
assertCorrectSetup("jdbc-config-pattern.xml", "dataSource");
@@ -169,4 +174,16 @@ public class JdbcNamespaceIntegrationTests {
}
}
private void assertCorrectSetupAndCloseContextForSingleDataSource(String file, int count) {
ConfigurableApplicationContext context = context(file);
try {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, count);
}
finally {
context.close();
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd">
<jdbc:embedded-database>
<jdbc:script location="classpath:org/springframework/jdbc/config/db-schema.sql" />
<jdbc:script location="classpath:org/springframework/jdbc/config/db-test-data.sql" />
</jdbc:embedded-database>
</beans>