Browse Source
- Extract code examples to separate Java, Kotlin, and XML files - Add Kotlin configuration sample alongside Java - Change "Java Config" terminology to "Programmatic Configuration" - Use include-code directive for better maintainability See gh-36323 Signed-off-by: jisub-dev <kimjiseob1209@gmail.com>pull/36433/head
4 changed files with 139 additions and 35 deletions
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* Copyright 2002-present 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.transaction.declarative.annotations; |
||||
|
||||
import javax.sql.DataSource; |
||||
|
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
||||
import org.springframework.transaction.PlatformTransactionManager; |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement; |
||||
|
||||
// tag::snippet[]
|
||||
@Configuration |
||||
@EnableTransactionManagement |
||||
public class AppConfig { |
||||
|
||||
@Bean |
||||
public FooService fooService() { |
||||
return new DefaultFooService(); |
||||
} |
||||
|
||||
@Bean |
||||
public PlatformTransactionManager txManager(DataSource dataSource) { |
||||
return new DataSourceTransactionManager(dataSource); |
||||
} |
||||
} |
||||
// end::snippet[]
|
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
/* |
||||
* Copyright 2002-present 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.transaction.declarative.annotations |
||||
|
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager |
||||
import org.springframework.transaction.PlatformTransactionManager |
||||
import org.springframework.transaction.annotation.EnableTransactionManagement |
||||
import javax.sql.DataSource |
||||
|
||||
// tag::snippet[] |
||||
@Configuration |
||||
@EnableTransactionManagement |
||||
class AppConfig { |
||||
|
||||
@Bean |
||||
fun fooService(): FooService { |
||||
return DefaultFooService() |
||||
} |
||||
|
||||
@Bean |
||||
fun txManager(dataSource: DataSource): PlatformTransactionManager { |
||||
return DataSourceTransactionManager(dataSource) |
||||
} |
||||
} |
||||
// end::snippet[] |
||||
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<!-- tag::snippet[] --> |
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:aop="http://www.springframework.org/schema/aop" |
||||
xmlns:tx="http://www.springframework.org/schema/tx" |
||||
xsi:schemaLocation=" |
||||
http://www.springframework.org/schema/beans |
||||
https://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/tx |
||||
https://www.springframework.org/schema/tx/spring-tx.xsd |
||||
http://www.springframework.org/schema/aop |
||||
https://www.springframework.org/schema/aop/spring-aop.xsd"> |
||||
|
||||
<!-- this is the service object that we want to make transactional --> |
||||
<bean id="fooService" class="x.y.service.DefaultFooService"/> |
||||
|
||||
<!-- enable the configuration of transactional behavior based on annotations --> |
||||
<!-- a TransactionManager is still required --> |
||||
<tx:annotation-driven transaction-manager="txManager"/> <!--1--> |
||||
|
||||
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
||||
<!-- (this dependency is defined somewhere else) --> |
||||
<property name="dataSource" ref="dataSource"/> |
||||
</bean> |
||||
|
||||
<!-- other <bean/> definitions here --> |
||||
|
||||
</beans> |
||||
<!-- end::snippet[] --> |
||||
Loading…
Reference in new issue