[weld-dev] Passivating Capabilities check.

Pete Muir pmuir at redhat.com
Tue Feb 16 06:40:58 EST 2010


On 16 Feb 2010, at 10:11, Mark Struberg wrote:

> Hi!
> 
> I'm just curious how Weld manages to inject a Logger into a @SessionScoped (passivating!) bean.
> 
> In your example in 1.3.5 you wrote:
> 
>> class Loggers {
>>   @Produces Logger getLogger(InjectionPoint injectionPoint) {
>>       return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getSimpleName() );
>>   }
>> }
> 
> and 
>> @SessionScoped
>> public class Permissions implements Serializable {
>>   @Inject Logger log;
>> ...
> 
> but the Logger I know are actually not Serializable themselfs and since it is @Dependent scoped, we also don't use a proxy for it.

I think you must use a proxy.

> 
> I'd expected a DeploymentException thrown at startup in this case, but Weld actually seems to only checks passivation stuff for NormalBeans. Anyway, once the session get's passivated, you'll see a fine NotSerializableException.

Well, the passivation capability is checked (of Permissions), which includes checking whether the producer method is passivation capable (it is, even though Logger isn't serializable, it also isn't final, so you might return a serializable subclass).

I would however expect Weld to throw an IllegalProductException - I wrote this test which shows it does :-)

http://fisheye.jboss.org/browse/weld/core/trunk/tests/src/test/java/org/jboss/weld/tests/serialization/SerializationTest.java?r=5841#l45


More information about the weld-dev mailing list