2013-06-13 3 views
2

Glassfish 3.1.2에서 JDK 1.6을 배포하고 실행하는 코드 세트가 있습니다.CDI 추상 클래스에 삽입

org.jboss.weld.exceptions.IllegalArgumentException: WELD-001407 Cannot declare an injection point with a type variable: [BackedAnnotatedField] @Inject protected com.co.ejb.web.AjaxGridServlet.sourceInstance 
at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:82) 
at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:68) 
at org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget(BeanManagerImpl.java:1039) 
at org.jboss.weld.manager.BeanManagerImpl.fireProcessInjectionTarget(BeanManagerImpl.java:1197) 
at org.glassfish.weld.WeldDeployer.firePITEvent(WeldDeployer.java:390) 
at org.glassfish.weld.WeldDeployer.fireProcessInjectionTargetEvents(WeldDeployer.java:360) 
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:212) 
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131) 
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:493) 
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219) 
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:537) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108) 
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762) 
at org.glassfish.deployment.autodeploy.AutoOperation.run(AutoOperation.java:164) 
at org.glassfish.deployment.autodeploy.AutoDeployer.deploy(AutoDeployer.java:595) 
at org.glassfish.deployment.autodeploy.AutoDeployer.deployAll(AutoDeployer.java:482) 
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:410) 
at org.glassfish.deployment.autodeploy.AutoDeployer.run(AutoDeployer.java:401) 
at org.glassfish.deployment.autodeploy.AutoDeployService$1.run(AutoDeployService.java:233) 
at java.util.TimerThread.mainLoop(Timer.java:555) 
at java.util.TimerThread.run(Timer.java:505) 
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001407 Cannot declare an injection point with a type variable: [BackedAnnotatedField] @Inject protected com.co.ejb.web.AjaxGridServlet.sourceInstance 
at org.jboss.weld.bootstrap.Validator.checkFacadeInjectionPoint(Validator.java:765) 
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDefinitionErrors(Validator.java:352) 
at org.jboss.weld.injection.producer.InjectionTargetService.validateProducer(InjectionTargetService.java:39) 
at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:79) 
... 24 more 

가 문제의 파일은 다음과 같습니다 : 확장

BaseJasonServlet

public abstract class BaseJsonServlet extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     doProcess(request, response); 
    } 

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     doProcess(request, response); 
    } 

    protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     response.setContentType("application/json"); 
     response.setCharacterEncoding("UTF-8"); 
     this.process(request, response); 
    } 

    protected abstract void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; 
} 

AjaxGridServlet 우리는 글래스 피시 4 JDK 1.7로 업데이트 할 경우, 우리는 응용 프로그램을 배포하려고 다음과 같은 오류가 BaseJsonServlet. 이 문제는 TSource 인스턴스를 삽입하는이 파일에 있습니다.

public abstract class AjaxGridServlet<TSource extends AjaxGridSource<?,?>> extends BaseJsonServlet { 
    private static final long serialVersionUID = 1L; 

    @Inject 
    protected Instance<TSource> sourceInstance; 

    @Override 
    protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

     TSource source= sourceInstance.get(); 
     source.process(request, response); 
     response.getWriter().write(source.toJsonString()); 
     } 
} 

AjaxGridServlet은 다음 어떤 도움을 크게 감상 할 수 것 webservlet

@WebServlet("/api/admin-dashboard") 
public class AdminDashboard extends AjaxGridServlet<AdminDashboardSource> { 
    private static final long serialVersionUID = 1L; 
} 

에 의해 확장됩니다. 감사.

답변

3

메시지에서 알 수있는 것은 유형 변수가있는 인스턴스를 가질 수 없다는 것입니다. 즉, TSource을 사용할 수 없습니다.

대신 Instance<AjaxGridSource>을 사용해야합니다. 이 반사는 일반적인 인수의 적절한 실행시의 형태를 감지하기가 매우 복잡하기 때문에

+0

응용 프로그램을 배포하지만 서블릿이 작동하지 않는다고 바꿀 때. org.jboss.weld.exceptions.UnsatisfiedResolutionException을 반환합니다 : WELD-001308 Types에 대한 빈을 모두 확인할 수 없습니다 : [class com.co.ejb.web.AjaxGridSource]; 바인딩 : [QualifierInstance {annotationClass = interface javax.enterprise.inject.Default, values ​​= {}, hashCode = -1237982948}] – user2340647

+0

이는 컨텍스트에서 그러한 bean이 없다는 것을 의미합니까? – Bozho

+0

AjaxGridSource는 그것을 확장하는 30 가지 이상의 클래스를 가진 추상 클래스입니다. 우리가 인스턴스 >을 수행하면 org.jboss.weld.exceptions.AmbiguousResolutionException으로 끝납니다 : WELD-001318 ... – user2340647

1

@Inject 
protected Instance<AjaxGridSource> sourceInstance; 

을보십시오.

+0

AjaxGridSource는 추상 클래스이고 서블릿은 사용할 소스를 지정합니다.하지만 개선/리 팩터를 제안하는 방법은 없습니다. 예를 들어 내가 게시 한 서블릿은 AdminDashboardSource 소스를 사용합니다. – user2340647

+0

어떤 이유인지 그것은'AdminDashboard'를 발견 할 수 없습니다. 'beans.xml' 파일이 누락 되었습니까? 아니면 그렇지 않은 경우 abstract 클래스에 대해 ** Producer **를 작성해보십시오. – darijan

+0

beans.xml이 누락되지 않았습니다. 주입은 응용 프로그램의 다른 영역에서 작동합니다. 이 코드는 EE 6 및 Glassfish 3.1.2와 함께 작동하여 EE 7 및 Glassfish 4로 업그레이드하여이 문제를 일으 킵니다. CDI 1.1에서 타입 변수를 가진 인스턴스를 생성 할 수없는 것이 있습니까? – user2340647

0

주입을 하위 클래스로 이동했습니다.

관련 문제