myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernhard Huemer <bernhard.hue...@gmail.com>
Subject Re: Myfaces-1.2.1-snapshot: Spring injected bean not available in @PostContruct method
Date Fri, 18 Jan 2008 10:53:03 GMT
Hello,

most probably he's injecting the Spring bean using managed-properties, 
i.e. I think his managed bean definition looks like the following:

<managed-bean>
   <managed-bean-name>...</managed-bean-name>
   ...

   <managed-property>
     <property-name>dataService</property-name>
     <value>#{dataService}</value>
   </managed-property>
</managed-bean>

However, there's a bug in MyFaces as it calls methods being annotated 
with @PostConstruct before all properties have been injected. I have 
already created a JIRA Issue, but I haven't got the time to fix this bug 
so far. Therefore I'd recommend you to define alle your beans in Spring 
directly, just as Gerhard has already mentioned.

regards,
Bernhard

On 01/18/2008 +0100,
"Gerald Müllan" <gerald.muellan@gmail.com> wrote:
> Hi,
> 
> Do you have the managed bean in faces-config.xml defined oder via
> spring configuration file?
> MyFaces should not be responsible for injecting a spring bean. This is
> done when using Spring beans only.
> 
> I would suggest to define it directly in Spring an use Spring`s
> init-method approach.
> 
> cheers,
> 
> Gerald
> 
> On Jan 17, 2008 10:11 PM, Zheng, Xiahong <Xiahong.Zheng@fmr.com> wrote:
>>
>>
>> In my managed bean, I have a service bean configured and injected by spring
>> as in the following,
>>
>> private DataService dataService;
>>
>> @PostConstruct
>> public void retrieveData() {
>>         dataService.retrieveData();
>> }
>>
>> Public void setDataService(DataService dataService) {
>>         this.dataService = dataService;
>> }
>>
>> Using RI, dataService is already injected before retrieveData method is
>> called. However, this is not the case with myfaces. It seems that spring
>> injection happens much later resulting in NPE thrown in the method. Is this
>> expected with myfaces inplementation or a bug?
>>


Mime
View raw message