Glassfish 4 scans for @PostConstruct with CDI disabled

后端 未结 2 1559
粉色の甜心
粉色の甜心 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:07

    You can solve this issue first by adding a web.xml with metadata-complete="true". Next you will want to make sure your context are in the Web root Directory /WEB-INF/.

    With this glassfish can load all @PostConstructSpring dependencies.

    More of a work around in my opinion.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题