Glassfish 4 scans for @PostConstruct with CDI disabled

后端 未结 2 1578
粉色の甜心
粉色の甜心 2021-01-14 16:52

I\'m doing and upgrade from Glassfish 3.1.2.2 to Glassfish 4.1 for a set of Spring applications. Since I use the Spring t

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 17:24

    Annotation @PostConstruct is a general annotation used in any dependency injection mechanism. The Javadoc explicitely states that, unless used within an interceptor, it must be put on a method, which has void return type and throws no checked exceptions.

    It is weird that Spring allows checked exceptions on post-construct methods, as there is not way how to handle them. But as this requirement is only a validation and can be ignored, Spring probably ignores checked exceptions and Glassfish does not. There is possibly an unnecessary Glassfish feature, that it scans and validates all classes, even if not used in CDI or any other mechanism (EJB, ...)

    The best is to remove checked exceptions to align the code with the documentation and make it portable.

提交回复
热议问题