[cdi-dev] Unexplained change in behavior between Java EE 6 and Java EE 7

Jozef Hartinger jharting at redhat.com
Mon Dec 8 12:44:33 EST 2014


Hi Steve,

this is not caused by a change in the specification nor in Weld. It is 
probably a regression in GlassFish integration. The correct behavior is 
the former (2 instances) as that is aligned with how @Dependent 
instances work in general. If you need the bean instance to be shared 
across injection points, you can give it a scope other than @Dependent.

HTH,

Jozef

On 12/08/2014 06:08 PM, Steve Millidge wrote:
>
> Hi
>
> We are investigating a change in behaviour between Java EE 6 and Java 
> EE 7 and were wondering if this is a bug or a specification change;
>
> If there is a RequestScoped bean and SFSB like below, and I call 
> invokeStatefulService() on the Request Scoped Bean the behaviour 
> changes depending on Java EE version;
>
> On GFv3 and JBoss EAP 6 the method returns "init" implying we have 2 
> separate SFSB instances.
>
> and on GFv4 and WildFly the method returns "stateFromFirst" implying 
> there is 1 SFSB instance.
>
> I would’ve imagined that the second result i.e. 1 SFSB as there is 1 
> client bean which exists for the duration of the call is the correct 
> behaviour. However I am not sure.
>
> As both appservers above use JBoss Weld for CDI is this a Weld bug or 
> did the behaviour change between Java EE 6 and Java EE 7?
>
> @RequestScoped
>
> public class Injection {
>
>     @Inject
>
> StatefulService first;
>
>     @Inject
>
> StatefulService second;
>
>     public String invokeStatefulService(){
>
> first.setState("stateFromFirst");
>
>         return second.getState();
>
>     }
>
> }
>
> @Stateful
>
> public class StatefulService {
>
>     private String state;
>
>     @PostConstruct
>
>     public void init(){
>
> this.state = "init";
>
>     }
>
>     public void setState(String state) {
>
> this.state = state;
>
>     }
>
>     public String getState() {
>
>         return state;
>
>     }
>
> }
>
> Steve Millidge
> Director
>
> C2B2
> *The Leading Independent Middleware Experts.*
> T: 08450 539457*|*M: 07920 100626*|*W: www.c2b2.co.uk 
> <http://www.c2b2.co.uk/>*|*E: smillidge at c2b2.co.uk 
> <mailto:smillidge at c2b2.co.uk>
>
> Main SIgnature May 14
> ---------------------------------------------------------------------------------------------------------------
> C2B2 Consulting Limited, Malvern Hills Science Park, Geraldine Road, 
> Malvern, Worcestershire, WR14 3SZ
> Registered in England and Wales: 4563419, Registered Office: 
> Ardendale, Old Hollow, Malvern, Worcestershire
>
>
>
> _______________________________________________
> cdi-dev mailing list
> cdi-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/cdi-dev
>
> Note that for all code provided on this list, the provider licenses the code under the Apache License, Version 2 (http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this list, the provider waives all patent and other intellectual property rights inherent in such information.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/cdi-dev/attachments/20141208/aaffada0/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 20712 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/cdi-dev/attachments/20141208/aaffada0/attachment-0001.jpe 


More information about the cdi-dev mailing list