{"id":3811,"date":"2014-01-09T14:53:56","date_gmt":"2014-01-09T05:53:56","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=3811"},"modified":"2018-11-14T16:33:52","modified_gmt":"2018-11-14T07:33:52","slug":"spring4%e3%81%a7xml%e3%82%92%e6%9b%b8%e3%81%8b%e3%81%9a%e3%81%ab%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e3%83%88%e3%83%a9%e3%83%b3%e3%82%b6","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2014\/01\/09\/spring4%e3%81%a7xml%e3%82%92%e6%9b%b8%e3%81%8b%e3%81%9a%e3%81%ab%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e3%83%88%e3%83%a9%e3%83%b3%e3%82%b6\/","title":{"rendered":"Spring4\u3067XML\u3092\u66f8\u304b\u305a\u306b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u30d9\u30fc\u30b9\u306e\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u6709\u52b9\u306b\u3059\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>Spring Framework \u3067\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u306b\u306f\u3001\u3001\u3001<\/p>\n<ol>\n<li>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b &lt;tx:annotation-driven transaction-manager=\"txManager\"\/&gt; \u3068\u66f8\u304f\u3002<\/li>\n<li>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067 PlatformTransactionManager \u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u3092\u30b3\u30f3\u30c6\u30ca\u306b\u767b\u9332\u3059\u308b\u3002<\/li>\n<li>\u30af\u30e9\u30b9\u3084\u30e1\u30bd\u30c3\u30c9\u306b @Transactional \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3002<\/li>\n<\/ol>\n<p>\u3068\u3044\u3046\u3084\u308a\u65b9\u304c\u304a\u6c7a\u307e\u308a\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>Web \u4e0a\u3067\u691c\u7d22\u3057\u3066\u3082\u4e0a\u8a18\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3060\u3051\u3067\u5b8c\u7d50\u3057\u305f\u3044\u3067\u3059\u3002<\/p>\n<p>\u8abf\u3079\u305f\u3068\u3053\u308d Spring Framework \u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u8a18\u8f09\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/docs.spring.io\/spring\/docs\/4.0.0.RELEASE\/spring-framework-reference\/htmlsingle\/#tx-decl-explained\">11.5.1 Understanding the Spring Framework\u2019s declarative transaction implementation<\/a><\/p>\n<p>\u3053\u3053\u3092\u8aad\u3080\u3068\u3001<\/p>\n<ol>\n<li>@Configuration \u3092\u4ed8\u3051\u305f\u30af\u30e9\u30b9\u306b @EnableTransactionManagement \u3092\u4ed8\u3051\u308b\u3002<\/li>\n<li>PlatformTransactionManager \u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u3092\u30b3\u30f3\u30c6\u30ca\u306b\u767b\u9332\u3059\u308b\u3002<\/li>\n<li>\u30af\u30e9\u30b9\u3084\u30e1\u30bd\u30c3\u30c9\u306b @Transactional \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3002<\/li>\n<\/ol>\n<p>\u3068\u3044\u3046\u624b\u9806\u3067\u3067\u304d\u308b\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u30b3\u30fc\u30c9\u306b\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:java decode:true\">import javax.sql.DataSource;\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.context.ApplicationContext;\r\nimport org.springframework.context.annotation.AnnotationConfigApplicationContext;\r\nimport org.springframework.context.annotation.Bean;\r\nimport org.springframework.context.annotation.ComponentScan;\r\nimport org.springframework.context.annotation.Configuration;\r\nimport org.springframework.jdbc.datasource.DataSourceTransactionManager;\r\nimport org.springframework.jdbc.datasource.SimpleDriverDataSource;\r\nimport org.springframework.stereotype.Component;\r\nimport org.springframework.transaction.PlatformTransactionManager;\r\nimport org.springframework.transaction.annotation.EnableTransactionManagement;\r\nimport org.springframework.transaction.annotation.Transactional;\r\n\r\n\/\/ 1. @Configuration \u3092\u4ed8\u3051\u305f\u30af\u30e9\u30b9\u306b @EnableTransactionManagement \u3092\u4ed8\u3051\u308b\r\n@Component\r\n@Configuration\r\n@ComponentScan\r\n@EnableTransactionManagement\r\npublic class App {\r\n\r\n    @Autowired\r\n    private DataSource dataSource;\r\n\r\n    public static void main(String[] args) {\r\n        ApplicationContext context = new AnnotationConfigApplicationContext(App.class);\r\n        context.getBean(App.class).run();\r\n    }\r\n\r\n    \/\/ 3. \u30af\u30e9\u30b9\u3084\u30e1\u30bd\u30c3\u30c9\u306b @Transactional \u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\r\n    private void run() {\r\n        \/\/ ...\r\n    }\r\n\r\n    @Bean\r\n    protected DataSource createDataSource() {\r\n        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();\r\n        dataSource.setDriverClass(org.postgresql.Driver.class);\r\n        dataSource.setUrl(\"jdbc:postgresql:\/\/localhost\/spring4_sample\");\r\n        return dataSource;\r\n    }\r\n\r\n    \/\/ 2. PlatformTransactionManager \u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u3092\u30b3\u30f3\u30c6\u30ca\u306b\u767b\u9332\u3059\u308b\r\n    @Bean\r\n    @Autowired\r\n    protected PlatformTransactionManager createTransactionManager(DataSource dataSource) {\r\n        return new DataSourceTransactionManager(dataSource);\r\n    }\r\n\r\n}<\/pre>\n<p>\u5168\u3066 XML\uff08\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\uff09\u30ec\u30b9\u3067\u958b\u767a\u3067\u304d\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u3002<\/p>\n<p>Spring4 \u306f\u3082\u3063\u3068\u8abf\u3079\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>Spring Framework \u3067\u30c8\u30e9\u30f3\u30b6\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3046\u306b\u306f\u3001\u3001\u3001<\/p>\n<p>\t\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b &lt;tx:annotation-driven transaction-manager=\"txManager\"\/&gt; \u3068\u66f8\u304f\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2014\/01\/09\/spring4%e3%81%a7xml%e3%82%92%e6%9b%b8%e3%81%8b%e3%81%9a%e3%81%ab%e3%82%a2%e3%83%8e%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%99%e3%83%bc%e3%82%b9%e3%81%ae%e3%83%88%e3%83%a9%e3%83%b3%e3%82%b6\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[57,122],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3811"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=3811"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3811\/revisions"}],"predecessor-version":[{"id":17886,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/3811\/revisions\/17886"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=3811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=3811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=3811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}