struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bartłomiej N (Jira) <j...@apache.org>
Subject [jira] [Commented] (WW-5089) @PreDestroy callbacks not invoked on injected beans
Date Wed, 16 Sep 2020 05:50:00 GMT

    [ https://issues.apache.org/jira/browse/WW-5089?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17196692#comment-17196692
] 

Bartłomiej N commented on WW-5089:
----------------------------------

Placing @RequestScoped on action doesn't work, in must mu placed on bean injected into action.
If it can't be solved easily, then it should be pointed out in documentation that deafult
scope for beans doesn't bind to scope of an action.

> @PreDestroy callbacks not invoked on injected beans
> ---------------------------------------------------
>
>                 Key: WW-5089
>                 URL: https://issues.apache.org/jira/browse/WW-5089
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - CDI
>    Affects Versions: 2.5.22
>         Environment: Apache Tomcat 9.0.31, Open JDK 13.0.2
>            Reporter: Bartłomiej N
>            Priority: Major
>
> I have web app deployed on tomcat with:
> {code:xml}
>         <dependency>
>             <groupId>org.apache.struts</groupId>
>             <artifactId>struts2-core</artifactId>
>             <version>2.5.22</version>
>         </dependency>
>       <dependency>
>             <groupId>org.apache.struts</groupId>
>             <artifactId>struts2-cdi-plugin</artifactId>
>             <version>2.5.22</version>
>         </dependency>
>         <dependency>
>             <groupId>org.jboss.weld.servlet</groupId>
>             <artifactId>weld-servlet-core</artifactId>
>             <version>3.1.5.Final</version>
>         </dependency>
> {code}
>  and:
> {code:xml}
> <listener>
>  <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
> </listener>
> <resource-env-ref>
>  <resource-env-ref-name>BeanManager</resource-env-ref-name>
>  <resource-env-ref-type>
>  javax.enterprise.inject.spi.BeanManager
>  </resource-env-ref-type>
> </resource-env-ref>
> {code}
>  
> as CDI bootstrap in web.xml and empty beans.xml in META-INF directory.  There is also
context.xml for Tomcat in webapp/META-INF:
> {code:xml}
> <?xml version='1.0' encoding='utf-8'?>
> <Context>
>     <Resource name="BeanManager"
>               auth="Container"
>               type="javax.enterprise.inject.spi.BeanManager"
>               factory="org.jboss.weld.resources.ManagerObjectFactory"/>
> </Context>
> {code}
> In app there is a simple CDI bean:
> {code:java}
> public class CDIBean {
>     @PostConstruct
>     private void postConstruct() {
>        //some code
>     }
>     @PreDestroy
>     private void preDestroy() {
>      //some code
>     }
> }
> {code}
> when is use it in Struts action:
> {code:java}
> class MyAction extends ActionSupport implements SessionAware {
>     @Inject
>     private CDIBean bean;
>     Strign execute() {
>        //some code
>     }
> }
> {code}
> @postConstruct callback is invoked and bean is injected correctly, but after request
completion @preDestroy is not invoked.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message