我正在尝试在我的BackingBean中注入拦截器,请参阅:
@SimpleAsync
@Interceptor
public class SimpleAsyncImpl implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Inject
ScheduleManager sm;
Logger logger = Logger.getLogger(getClass().getName());
@AroundInvoke
public Object callAsync(final InvocationContext ctx) throws Exception {
logger.fine("Invokingchronous method: " + ctx.getMethod().getName());
// Schedule 0 seconds from now
sm.schedule(new Runnable() {
@Override
public void run() {
try {
ctx.proceed();
} catch (Exception e) {
logger.log(Level.SEVERE, "Exception from asynchronously invoked method.", e);
}
}
}, 0);
return null;
}
}
@InterceptorBinding
@Target(value={ElementType.METHOD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface SimpleAsync {
}
现在我在BackingBean中使用了:
@Named("acervoVideoDetalheMB")
@ConversationScoped
public class AcervoVideoDetalheMBImpl extends BasicDetailMBImpl<AcervoVideo> {
@SimpleAsync
private void initEnvioVideo(final Part partVideo, String originalName, final String target) {
}
@SimpleAsync是我的拦截器,你可以看到AcervoVideoDetalheMBIMpl的构造函数需要一个ParametrizedType,即AcervoVideo bean。在我的postConstruct中,我有以下内容:
@PostConstruct
public void postConstruct() {
try {
ParameterizedType superClass = (ParameterizedType) getClass()
.getGenericSuperclass();
Class<Bean> type = (Class<Bean>) superClass
.getActualTypeArguments()[0];
return type.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
return null;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
我收到以下错误:
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
但是如果我删除了@SimpleAsync注释,一切正常,因为我禁用了Interceptor。