[jboss-user] [JBoss Seam] - Re: @Startup and Seam interceptor

xinhua do-not-reply at jboss.com
Thu Nov 29 10:48:53 EST 2007


hi,
yes, interceptor works fine with other component without @Startup 

At first, i have two annotations 

  | @Target(TYPE)
  | @Documented
  | @Retention(RUNTIME)
  | @Interceptors(KleberInterceptor.class)
  | public @interface Kleber 
  | {
  | 	
  | }
  | 



interceptor is supposed to check filed with @Jndi annotation and take the string from @jndi for jndi lookup

  | public class KleberInterceptor {
  | 
  | 	@PostConstruct
  | 	public Object jndiLookup(InvocationContext invocation )throws Exception{
  | 		Object target = invocation.getTarget();
  | 		Field[] fields = target.getClass().getDeclaredFields();
  | 		
  | 		try{
  | 			InitialContext ctx = new InitialContext();
  | 			for(Field field: fields){
  | 				Jndi jndi = field.getAnnotation(Jndi.class);
  | 				if(jndi!=null){
  | 					Object obj = ctx.lookup(jndi.value());
  | 					field.setAccessible(true);
  | 					field.set(target, obj);
  | 				}
  | 			}
  | 			
  | 		}catch(Exception ex){
  | 			ex.printStackTrace();
  | 		}
  | 		
  | 		return invocation.proceed();
  | 	}
  |         
  |        @AroundInvoke
  |        otherMethods............
  | 
  | 
  | }
  | 

I can not use @Kleber on a component which already has a @Startup, what i can do now ,is to write jndi lookup codes directly in @Startup component, and it works.....

is there any better way to inject jndi resouce in @Startup Seam component?




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4108946#4108946

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4108946



More information about the jboss-user mailing list