Issue 1:
Julian Sareyka opened SPR-8849 and commented

Hi,

I use an embedded database (HSQL) in my integration test suite. Its a maven project with TestNG.

<jdbc:embedded-database id="mirDataSource">
<jdbc:script location="classpath:db/schema.sql" />
<jdbc:script location="classpath:db/tables_hsqldb.sql" />
<jdbc:script location="classpath:db/package_verweildauer.sql" />
<jdbc:script location="classpath:db/data.sql" />
</jdbc:embedded-database>

I have one default context configuration (which includes the database) and several extensions:

for instance:

@ContextConfiguration("/spring/default.xml")
public class PodcastControllerTest extends AbstractTestNGSpringContextTests {...}

// and

@ContextConfiguration({ "/spring/components/amq-broker.xml", "/spring/default.xml" })
public class SophoraAvDocumentTest extends AbstractTestNGSpringContextTests {...}

When executing the tests with maven (maven-surefire), all the tests with the first configuration reuse the same context (due to context caching). The first test-setup with the second configuration should create a fresh application context, but it fails with Database-Errors indicating, that the objects to create already exist. (I spent quite some time debugging the maven process).

Here is the maven surefire config:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<threadCount>1</threadCount>
<excludedGroups>slow,local</excludedGroups>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>

My theory is, that both contexts connect to the same database instance, because they are in the same vm and the name of the db-instance is the same:

EmbeddedDatabaseFactory.databaseName = "testdb";

I did not find a way to assign the name with the jdbc:embedded-database-Tag.

So I created a custom EmbeddedDatabaseBuilder which assigns a random name (UUID) to every new instance:

EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL).setName(UUID.randomUUID().toString());
for (String sqlResource : this.scripts) {
builder.addScript(sqlResource);
}
this.embeddedDatabase = builder.build();

With this one the errors are gone. Would it be a solution to add a configuration-option to jdbc:embedded-database for random db-instance names?

Affects: 3.1 GA

Issue Links:

#17432 Introduce database-name attribute in <jdbc:embedded-database /> ("depends on")

#17437 Document support for generating unique names for embedded databases in the reference manual ("is depended on by")

#15999 Embedded database connection closed by shutdown() method

#13560 Using multiple declarations of jdbc:embedded-database creates only one H2 instance per JVM

#12260 jdbc:datasource lacks 'name' attribute or related mechanism

6 votes, 7 watchers

Issue 2:
Tim Schafer opened SPR-671 and commented

2005-01-31 13:58:49 StandardContext[/kls2]Loading root WebApplicationContext

2005-01-31 13:58:49 StandardContext[/kls2]Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/classpath:/database.beans.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classpath:/database.beans.xml]

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classpath:/database.beans.xml]

at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:89)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:127)

at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.importBeanDefinitionResource(DefaultXmlBeanDefinitionParser.java:226)

at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:180)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:170)

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:129)

at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:144)

at org.springframework.context.support.AbstractXmlApplicationContext.refreshBeanFactory(AbstractXmlApplicationContext.java:79)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:249)

at org.springframework.web.context.support.XmlWebApplicationContext.refresh(XmlWebApplicationContext.java:131)

at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:167)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:101)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)

at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)

at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)

at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:922)

at org.apache.catalina.manager.HTMLManagerServlet.deployInternal(HTMLManagerServlet.java:271)

at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:95)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)

at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)

at java.lang.Thread.run(Thread.java:534)

Affects: 1.1.2

1 votes, 0 watchers