Spring Boot 1.3.1 の使用
@RestController がデフォルトで Transactionnal である理由がわかりません。ドキュメントでそう言っているものは見つかりませんでした。
以下のコントローラーのメソッド findOne() が Transactionnal であるという事実をプッシュする例:
@RestController
@RequestMapping("/books")
public class BookController {
@RequestMapping("/{id}")
public Book findOne(@PathVariable Long id) {
Book book = this.bookDao.findOneBookById(id);
// following line
// => triggers a select author0_.id as id1_0_0_ etc... // where author0_.id=?
System.out.println(book.getAuthor().getFirstname());
return book;
}
}
System.out.println(book.getAuthor().getFirstname()); の行 LazyInitiaizationFailure を発生させる必要がありますが、ここでは成功し、Author の選択をトリガーします。したがって、メソッド findOne はトランザクションのようです。Eclipse デバッガーを使用すると、補完的な選択をトリガーするのは実際にはこの行であると確信できます。しかし、なぜそのメソッドは transactionnal なのですか?
@Configuration
@ComponentScan(basePackageClasses = _Controller.class)
@Import(BusinessConfig.class)
public class WebConfig extends WebMvcConfigurerAdapter {
// ... here the conf to setup Jackson Hibernate4Module
}
@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement
@EntityScan(basePackageClasses = _Model.class)
@ComponentScan(basePackageClasses = { _Dao.class })
public class BusinessConfig {
}
@SpringBootApplication
public class BookstoreStartForWebEmbedded {
public static void main(String[] args) {
SpringApplication.run(BookstoreStartForWebEmbedded.class, args);
}
}
libs :
spring-boot-starter 1.3.1.RELEASE
spring-boot-starter-test : 1.3.1.RELEASE
spring-boot-starter-valisation : 1.3.1.RELEASE
spring-boot-starter-web : 1.3.1.RELEASE
spring-boot-starter-data-jpa : 1.3.1.RELEASE
postgresql: 9.4-1206-jdbc41
querydsl-jps:3.7.0
jackson-annotations:2.6.4
jackson-datatype-hibernate4:2.6.4
何か案が ?
それが機能である場合、私はそれをオフにしたいのですが...