1

Spring Bean を JSF Bean に注入しようとしています。Spring 3.1 と JSF 2 (Mojarra 2.1.7) を使用しています。

私の構成とコード、および以下にリストされている例外について多くを語らずに:

StudentService.java:

@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS)
public class StudentsService extends AbstractMaqraaService {

    @Override
    public Set<Class<?>> getTypes() {
        // TODO Auto-generated method stub
        return null;
    }

    public Student registerStudent(Student student) {
        return this.store(student);
    }

}

StudentRegistrationMBean.java:

@ManagedBean(name="studentRegistrationMBean") 
@SessionScoped
public class StudentRegistrationMBean extends AbstractMBean {

    private Student student;
    @ManagedProperty (value="#{studentsService}")
    private StudentsService studentsService;

    public StudentRegistrationMBean() {
        this.student = new Student();
    }

    /*Setters and getters omitted here only*/

    public String register() {

        studentsService.registerStudent(student);
        return "manageStudents";
    }
}

モジュール コンテキスト xml ファイルの Spring Bean:

<bean id="abstractMaqraaService" class="org.tts.maqraa.service.AbstractMaqraaService" abstract="true"/>

<bean id="studentsService" class="org.tts.maqraa.service.StudentsService" lazy-init="default" parent="abstractMaqraaService"/>

顔-config.xml:

...
<application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
...

出現:

TRACE [http-bio-8080-exec-3] (SpringBeanELResolver.java:53) - Successfully resolved variable 'studentsService' in Spring BeanFactory
DEBUG [http-bio-8080-exec-3] (AbstractBeanFactory.java:245) - Returning cached instance of singleton bean 'studentsService'
نوار 13, 2012 11:10:45 ص com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/teacher/registerNewStudent.xhtml]
com.sun.faces.mgbean.ManagedBeanCreationException: Unable to set property studentsService for managed bean studentRegistrationMBean
    at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:615)
    at com.sun.faces.mgbean.ManagedBeanBuilder.buildBean(ManagedBeanBuilder.java:133)
    ...
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: Cannot convert org.tts.maqraa.service.StudentsService@8f65bc0 of type class $Proxy10 to class org.tts.maqraa.service.StudentsService
    at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420)
    at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:47)
    at com.sun.faces.el.ELUtils.coerce(ELUtils.java:536)
    at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:592)
    at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606)
    ... 47 more

ERROR [http-bio-8080-exec-3] (MaqraaExceptionHandler.java:83) - Exception
javax.el.ELException: Cannot convert org.tts.maqraa.service.StudentsService@8f65bc0 of type class $Proxy10 to class org.tts.maqraa.service.StudentsService
    at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420)
    ...
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

私はGoogleで多くの検索を行いましたが、ここで多くの質問に私のような問題があることがわかりましたが、何も助けにはなりませんでした.私の特別なケースの解決策が見つかることを願っています!!

4

2 に答える 2

3

<aop:aspectj-autoproxy proxy-target-class="true"/>CGLIB ではなく JDK プロキシの使用を強制するために使用します

于 2012-05-27T08:14:14.877 に答える
0

このようにSpringサービスを注入する場合は、サービスのセッターを作成することを忘れないでください。

@ManagedProperty (value="#{studentsService}")
private StudentsService studentsService;

public void setStudentsService (StudentsService studentsService)
{
    this.studentsService = studentsService;
}

@Autowiredアノテーションを使用すると、これを行う必要はありませんでした。

この答えを見てくださいそれはあなたのプロキシを使用するためのインターフェースを使用しないことについてです。

于 2012-05-25T09:46:16.773 に答える