4 changed files with 101 additions and 109 deletions
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2002-2024 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.dataaccess.jdbc.jdbcembeddeddatabase; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; |
||||
|
||||
@Configuration |
||||
public class JdbcEmbeddedDatabaseConfiguration { |
||||
|
||||
// tag::snippet[]
|
||||
@Bean |
||||
DataSource dataSource() { |
||||
return new EmbeddedDatabaseBuilder() |
||||
.generateUniqueName(true) |
||||
.setType(EmbeddedDatabaseType.H2) |
||||
.addScripts("schema.sql", "test-data.sql") |
||||
.build(); |
||||
} |
||||
// end::snippet[]
|
||||
|
||||
} |
||||
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
/* |
||||
* Copyright 2002-2024 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.docs.dataaccess.jdbc.jdbcembeddeddatabase |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder |
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType |
||||
|
||||
@Configuration |
||||
class JdbcEmbeddedDatabaseConfiguration { |
||||
|
||||
// tag::snippet[] |
||||
@Bean |
||||
fun dataSource() = EmbeddedDatabaseBuilder() |
||||
.generateUniqueName(true) |
||||
.setType(EmbeddedDatabaseType.H2) |
||||
.addScripts("schema.sql", "test-data.sql") |
||||
.build() |
||||
// end::snippet[] |
||||
|
||||
} |
||||
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/jdbc |
||||
https://www.springframework.org/schema/context/spring-jdbc.xsd"> |
||||
|
||||
<!-- tag::snippet[] --> |
||||
<jdbc:embedded-database id="dataSource" generate-name="true" type="H2"> |
||||
<jdbc:script location="classpath:schema.sql"/> |
||||
<jdbc:script location="classpath:test-data.sql"/> |
||||
</jdbc:embedded-database> |
||||
<!-- end::snippet[] --> |
||||
|
||||
</beans> |
||||
Loading…
Reference in new issue