-- 开发数据源 --> <jdbc: embedded-database id="datasource"type="H2"> <jdbc: script location="com/hab schema.sql"/> <jdbc: script location="com/habum a/spitter/ab/jdbc/test-data. sql"/> </jdbc: embedded-database
-- DataSource --> <jdbc:embedded-database id="dataSource" generate-name="true" type="H2"> < location="classpath:h2/schema.sql"/> <jdbc:script location="classpath:h2/test-data.sql"/> </jdbc:embedded-database
<jdbc:embedded-database id="dataSource" type="H2"> <jdbc:script location="classpath*:schema.sql" /> <jdbc:script location="classpath*:test-data.sql" /> </jdbc:embedded-database> <jdbc:embedded-database 在<jdbc:embedded-database>配置中,可以配置多个<jdbc:script>元素,用于设置和初始化数据库:在这个例子中,schema.sql文件中包含用于创建数据表的关系;test-data.sql .addScript("classpath*:test-data.sql") .build(); } 可以看出,setType()方法的作用等同于<jdbc:embedded-database schema.sql" /> <jdbc:script location="classpath*:test-data.sql" /> </jdbc:embedded-database
<jdbc:embedded-database id="dataSource" generate-name="true"> <jdbc:script location="classpath:schema.sql "/> <jdbc:script location="classpath:test-data.sql"/> </jdbc:embedded-database> 当然还可以以编程方式创建嵌入式数据库 要指定数据库类型,在上面的XML片段中添加embedded-database属性并设置HSQL、H2或Derby。 EmbeddedDatabaseFactory.setGenerateUniqueDatabaseName() EmbeddedDatabaseBuilder.generateUniqueName() <jdbc:embedded-database
beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <beans profile="dev"> <jdbc:embedded-database location="classpath:schema.sql" /> <jdbc:script location="classpath:test-data.sql" /> </jdbc:embedded-database
"> <jdbc:embedded-database id="dataSource"> <jdbc:script location="classpath:com/bank/config schema.sql"/> <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/> </jdbc:embedded-database
"> <jdbc:embedded-database id="dataSource"> <jdbc:script location="classpath:com/bank/config schema.sql"/> <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/> </jdbc:embedded-database "> <beans profile="development"> <jdbc:embedded-database id="dataSource"> <jdbc /> <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/> </jdbc:embedded-database
www.springframework.org/schema/jdbc/spring-jdbc.xsd"> <beans profile="dev"> <jdbc:embedded-database schema.sql"/> <jdbc:script location="classpath:test-data.sql"/> </jdbc:embedded-database
嵌入的数据库现在可以被自动赋值不同的(unique)名字,且**<jdbc:embedded-database>支持新的属性database-name**。参考下面的“测试的改进”部分。 JDBC XML的命名空间支持一个新的属性database-name,位于**<jdbc:embedded-database>**中,允许开发者为嵌入的数据库设置不同的名字——例如,通过SpEl表达式或者被当前 ###6.2 数据访问的改进 jdbc:initialize-database和jdbc:embedded-database支持一个可配置的分隔符应用于任何脚本。
"> <jdbc:embedded-database id="dataSource"> <jdbc:script location="classpath:com/bank/config schema.sql"/> <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/> </jdbc:embedded-database "> <beans profile="development"> <jdbc:embedded-database id="dataSource"> <jdbc /> <jdbc:script location="classpath:com/bank/config/sql/test-data.sql"/> </jdbc:embedded-database