[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-1584) @Logger and Spring beans

Michael Youngstrom (JIRA) jira-events at lists.jboss.org
Fri Jun 29 15:16:57 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBSEAM-1584?page=comments#action_12367350 ] 
            
Michael Youngstrom commented on JBSEAM-1584:
--------------------------------------------

>What happens if I add <seam:component/>? Is this bean no longer the same in spring context and seam context? 

The bean will be the same in spring and seam.  Except now it will be a spring bean and seam bean at the same time. :)

Then @Logger should work fine.

> @Logger and Spring beans
> ------------------------
>
>                 Key: JBSEAM-1584
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-1584
>             Project: JBoss Seam
>          Issue Type: Feature Request
>          Components: Spring
>    Affects Versions: 2.0.0.BETA1
>            Reporter: Magnus Heino
>         Assigned To: Michael Youngstrom
>
> It would be nice if spring beans could be scanned for @Logger and injected with Log instances just like seam components.
> Using the code below, you can add this to applicationContext.xml...
> <bean class="org.jboss.seam.ioc.spring.LoggerPostProcessor" />
> ...to have all spring beans scanned for @Logger and have a Log instance injected, just like seam components. Then you can access the same context and log functionallity in your spring beans as in your seam components.
> I guess the seam spring namespace could be extended with <seam:logger/> to make it even more simple to use.
> package org.jboss.seam.ioc.spring;
> import java.lang.reflect.Field;
> import org.jboss.seam.annotations.Logger;
> import org.jboss.seam.log.Logging;
> import org.springframework.beans.BeansException;
> import org.springframework.beans.factory.config.BeanPostProcessor;
> import org.springframework.util.ReflectionUtils;
> import org.springframework.util.StringUtils;
> import org.springframework.util.ReflectionUtils.FieldCallback;
> public class LoggerPostProcessor implements BeanPostProcessor {
> 	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
> 		return bean;
> 	}
> 	public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
> 		ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
> 			public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
> 				if (field.isAnnotationPresent(Logger.class)) {					
> 					String category = field.getAnnotation(Logger.class).value();
> 					
> 					if(!StringUtils.hasText(category)) {
> 						category = bean.getClass().getName();
> 					}
> 							
> 					ReflectionUtils.makeAccessible(field);					
> 					field.set(bean, Logging.getLog(category));
> 				}
> 			}
> 		});
> 		return bean;
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list