我有一个泛型类DefaultBatchReportService . 我想将不同的POJO类,Service&Dao传递给这个泛型类 .

但是,我发现使用内部自动装配泛型类将特定类传递给泛型抽象类时遇到了困难 .

我得到的错误如下:

2016年2月2日下午1:49:10 com.sun.faces.application.view.ViewScopeManager 2016年2月2日下午1:49:10 com.sun.faces.lifecycle.InvokeApplicationPhase执行警告:创建名称为'的bean时出错rt001Bean':自动连接依赖项的注入失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.edgar.report.core.DefaultBatchReportService com.edgar.test.RT001Bean.bReportController;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'defaultBatchReportService'的bean时出错:注入自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.edgar.report.core.SingleReportService com.edgar.report.core.DefaultBatchReportService.singleReportService;嵌套异常是org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义[com.edgar.report.core.SingleReportService]类型的限定bean:期望的单个匹配bean但找到3:RT001Service,RT002Service,RT003Service org.springframework.beans .factory.BeanCreationException:创建名为'rt001Bean'的bean时出错:注入自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.edgar.report.core.DefaultBatchReportService com.edgar.test.RT001Bean.bReportController;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名为'defaultBatchReportService'的bean时出错:注入自动连接的依赖项失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段:private com.edgar.report.core.SingleReportService com.edgar.report.core.DefaultBatchReportService.singleReportService;嵌套异常是org.springframework.beans.factory.NoUniqueBeanDefinitionException:没有定义[com.edgar.report.core.SingleReportService]类型的限定bean:期望的单个匹配bean但在org.springframework中找到3:RT001Service,RT002Service,RT003Service . bean.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)位于org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) . org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)中的doCreateBean(AbstractAutowireCapableBeanFactory.java:537)org.springframework.beans.factory.support.AbstractBeanFactory $ 2.getObject(AbstractBeanFactory.java:342) )在org.sp的com.gitgub.javaplugs.jsf.ViewScope.get(ViewScope.java:69) ringframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:337)位于org.springframework.context.support.AbstractApplicationContext的org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) . getBean(AbstractApplicationContext.java:956)位于org.springframework.beans.factory.access.el.SpringBeanELResolver.getValue(SpringBeanELResolver.java:55)的com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.un.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)atg.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)at org.apache.el.parser.AstValue.getTarget (AstValue.java:93)org.apache.el.parser.AstValue.invoke(AstValue.java:259)位于com.sun.faces的org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273) . facers.el.TagMethodExpression.invoke(TagMethodExpression.java:105)at javax.faces.component.MethodBindingMethodExpressi onAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)位于org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)的com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)javax.faces.component.UICommand.broadcast(UICommand.java:315)位于javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)的javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)在com.sun.faces.lifecycle.LifecycleImpl.exe,com.sun.faces.lifecycle.Phase . (LifecycleImpl.java:198)位于org.apache.catalina的org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)的javax.faces.webapp.FacesServlet.service(FacesServlet.java:658) . core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)org.apache.tomcat.websocket org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)中的.server.WsFilter.doFilter(WsFilter.java:52)org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) )在org.springframework的org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:316)org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115) . security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)位于org.springframework.security.web.access的org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330) . inter.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)位于com.edgar.bean.MDCFilterSecurityInterceptor.doFilter的org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)中( MDCFilterSecurityInterceptor.java:24)org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)atg.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)at org位于org.springframework.security.web.FilterChainProxy的org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)中的.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)位于org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java)的org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)上的$ VirtualFilterChain.doFilter(FilterChainProxy.java:330) :330)org.springframework.secu上的org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:168) rity.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)位于org.springframework.security.web.FilterChainProxy $ VirtualFilterChain的org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) . 在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)的org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)中的doFilter(FilterChainProxy.java:330) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)位于org.springframework.security的org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)位于org.springframework.security.web.FilterCh的org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)的.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:120) ainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java: 107)在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)at atorg.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)位于org.springframework.security的org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) . web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter( FilterChainProxy.java:330)在org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)在org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)在org.springframework.web .filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)位于org.apache.catalina.core的org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) . ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)atg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)at org位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)的.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain)的.java:208)在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)在org.apache.catalina . authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)在org.apac he.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter . Java的:423)在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)在org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:620)在org.apache.tomcat.util .net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:318)在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:615 )atg.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:745)

批量报告服务:

@Component
@Scope("prototype")
public class DefaultBatchReportService <T extends SingleReportService, I extends ReportInputParam, M extends ReportMeta, MD extends ReportMetaDetail, C extends ReportContent, P extends ReportDao<I , M, MD, C>> {
    @Setter
    private I inputParam;
    @Setter
    private M meta;

    @Autowired
    @Setter
    private T singleReportService;
    @Autowired
    @Setter
    private P reportDao; 
}

Managed Bean类:

@Component
@SpringScopeView
@Getter
@Setter
public class RT001Bean extends BaseBean {
    @Autowired
    private DefaultBatchReportService<RT001Service, RT001_InputParam, RT001_Meta, RT001_Meta.Detail, RT001_Content, RT001Dao> bReportController;

    private RT001_InputParam inputParam;

    public void generateBatchReport() {

        //Start Report Generation
        try {
            bReportController.doSomething(inputParam);
            ....
        } catch (CustomException e) {
            // Print Error Message

    }
}

在这个项目中,我的团队正在使用JSF-Spring集成框架 . 正常标准的控件注入工作正常(没有通用类型) .

在我的项目中有多个具有相同过程的批处理报告,这就是为什么我想通过将不同的类传递给它来使用DefaultBatchReportService来处理每个BatchReport . (RT001 ...,RT002 ...,RT003 ..)然后,开发人员可以专注于绘制“单一”报告 .

抱歉我的英语不好:/