I have spring XML that enables me to start H2 database in server mode using the following configuration:
<beans profile="test-h2">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:target/h2/pps;AUTO_SERVER=TRUE"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="entityManagerFactory" parent="entityManagerFactoryCommonParent">
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
I want to convert to java based configuration. I have seem a post here: Start and setup in-memory DB using Spring asking somewhat the same question and I have looked at http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html#jdbc-embedded-database-support for Embedded Database but it does not say how to set H2 mode to Server mode. It is starting the server for me in "mem" mode only.
I have the following code:
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
builder.setType(EmbeddedDatabaseType.H2);
builder.setName(DATABASE_NAME);
builder.addScript(H2_SCHEMA);
builder.addScript(H2_TEST);
return builder.build();
Maybe using EmbeddedDatabaseBuilder(ResourceLoader) might work. Does anyone has some sample code for it?