java - CDI Interceptor not kicking in -
my interceptor not kicking in when should, though it's registered in beans , files provide no warnings. missing?
edit 1: want able log each time function in genres.java
invoked , left, not getting output @ configuration.
edit 2: after following svetlin's advice apply breakpoints, can confirm code never reaches neither interceptor or producer.
beans.xml
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" version="1.1" bean-discovery-mode="all"> <interceptors> <class>no.krystah.log.logginginterceptor</class> </interceptors> </beans>
logginginterceptor.java
package no.krystah.log; import javax.inject.inject; import javax.interceptor.aroundconstruct; import javax.interceptor.aroundinvoke; import javax.interceptor.interceptor; import javax.interceptor.invocationcontext; import org.slf4j.logger; @log @interceptor public class logginginterceptor { @inject logger logger; @aroundconstruct private void init(invocationcontext ic) throws exception { logger.info("entering constructor"); try { ic.proceed(); } { logger.info("exiting constructor"); } } @aroundinvoke public object logmethod(invocationcontext ic) throws exception { logger.info(ic.gettarget().tostring()+" - "+ ic.getmethod().getname()); try { return ic.proceed(); } { logger.info(ic.gettarget().tostring()+ " - "+ ic.getmethod().getname()); } } }
log.java
package no.krystah.log; import static java.lang.annotation.elementtype.method; import static java.lang.annotation.elementtype.type; import static java.lang.annotation.retentionpolicy.runtime; import java.lang.annotation.inherited; import java.lang.annotation.retention; import java.lang.annotation.target; import javax.interceptor.interceptorbinding; @inherited @interceptorbinding @retention(runtime) @target({method, type}) public @interface log { }
loggerproducer.java
package no.krystah.log; import javax.enterprise.inject.produces; import javax.enterprise.inject.spi.injectionpoint; import javax.faces.bean.sessionscoped; import org.slf4j.logger; import org.slf4j.loggerfactory; @sessionscoped public class loggerproducer { @produces public logger producelogger(injectionpoint injectionpoint) { return loggerfactory.getlogger(injectionpoint.getmember().getdeclaringclass().getname()); } }
genres.java
package no.krystah; import java.util.arraylist; import java.util.list; import javax.annotation.resource; import javax.faces.application.facesmessage; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; import javax.faces.component.uicomponent; import javax.faces.component.uiinput; import javax.faces.context.facescontext; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; import javax.transaction.usertransaction; import no.krystah.entity.genre; import no.krystah.log.log; import org.slf4j.logger; import org.slf4j.loggerfactory; @log @managedbean @sessionscoped public class genres { public genres() { } /* functions */ }
i think problem @sessionscoped annotation using. import indicates using
import javax.faces.bean.sessionscoped;
please switch cdi one:
import javax.enterprise.context.sessionscoped;
also shouldn't use @managedbean annotation, please replace through java ee 7 one:
@named
Comments
Post a Comment