java.lang.IllegalStateException:找不到匹配的编辑器或转换策略

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42948013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 06:58:42  来源:igfitidea点击:

java.lang.IllegalStateException: no matching editors or conversion strategy found

javaspringhibernate

提问by Chaymae

So i'm building a spring 3.2.3.RELEASE / hibernate 4.0.1.FINAL application and i got the following exception

所以我正在构建一个 spring 3.2.3.RELEASE / hibernate 4.0.1.FINAL 应用程序,我得到以下异常

[2017-03-22 09:29:47,860] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory [localhost-startStop-1] Ignoring bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginService' defined in URL [jar:file:/D:/Programmes/apache-tomcat-7.0.33/webapps/perWeb/WEB-INF/lib/perService-2.0.jar!/applicationContext-transactional-service.xml]: Cannot resolve reference to bean 'loginServiceImpl' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginServiceImpl' defined in URL [jar:file:/D:/Programmes/apache-tomcat-7.0.33/webapps/perWeb/WEB-INF/lib/perService-2.0.jar!/applicationContext-simple-service.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'ma.dao.impl.GenericDAO' to required type 'ma.dao.IGenericDAO' for property 'dao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [ma.dao.impl.GenericDAO] to required type [ma.dao.IGenericDAO] for property 'dao': no matching editors or conversion strategy found

[2017-03-22 09:29:47,860] 调试 org.springframework.beans.factory.support.DefaultListableBeanFactory [localhost-startStop-1] 在 FactoryBean 类型检查中忽略 bean 创建异常:org.springframework.beans.factory.BeanCreationException:在 URL [jar:file:/D:/Programmes/apache-tomcat-7.0.33/webapps/perWeb/WEB-INF/lib/perService-2.0.jar!/applicationContext-transactional 中定义名称为“loginService”的 bean 创建时出错-service.xml]:在设置 bean 属性“target”时无法解析对 bean“loginServiceImpl”的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在 URL [jar:file:/D:/Programmes/apache-tomcat-7.0.33/webapps/perWeb/WEB-INF 中定义的名称为“loginServiceImpl”的 bean 创建时出错/lib/perService-2.0.jar!/applicationContext-simple-service.xml]: bean 初始化失败;嵌套异常是 org.springframework.beans.ConversionNotSupportedException:无法将 'ma.dao.impl.GenericDAO' 类型的属性值转换为属性 'dao' 所需的类型 'ma.dao.IGenericDAO';嵌套异常是 java.lang.IllegalStateException:无法将类型 [ma.dao.impl.GenericDAO] 的值转换为属性“dao”所需的类型 [ma.dao.IGenericDAO]:找不到匹配的编辑器或转换策略

Here is my beans: loginservice

这是我的 bean:loginservice

<bean id="loginService"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref bean="transactionManagerPER" />
        </property>
        <property name="target">
            <ref bean="loginServiceImpl" />
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="loadUserByUsername">
                    PROPAGATION_REQUIRED,-Exception
                </prop>
            </props>
        </property>
    </bean>

loginServiceImpl

登录服务实现

<bean id="loginServiceImpl"
          class="ma.service.login.LoginService">
        <property name="dao">
            <ref bean="userDAO" />
        </property>
    </bean>

UserDAO

用户DAO

<bean id="userDAO"
        class="ma.dao.impl.GenericDAO">
        <constructor-arg>
            <value>
                ma.dao.mappings.Utilisateur
            </value>
        </constructor-arg>
        <property name="sessionFactory">
            <ref bean="sessionFactoryPER" />
        </property>
    </bean>

Utilisateur.Java

实用程序.Java

@Entity
@NamedQueries(
        {
            @NamedQuery(name="findUtilisateurByName", 
                    query = "select user from Utilisateur user where user.login=:userName"
                    ) 
        }
)
public class Utilisateur implements java.io.Serializable {

    private static final long serialVersionUID = 7214071893495381842L;
    private Integer id;
    private Profil  profil;
    private String  nom;
    private String  prenom;
    private String  login;
    private String  passwd;

    public Utilisateur() {
    }

    public Utilisateur(Integer id) {
        this.id = id;
    }

    @Id @GeneratedValue
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne
    public Profil getProfil() {
        return profil;
    }

    public void setProfil(Profil profil) {
        this.profil = profil;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getPrenom() {
        return prenom;
    }

    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPasswd() {
        return passwd;
    }

    public void setPasswd(String passwd) {
        this.passwd = passwd;
    }
}

Am i missing somthing ? If you need more informations please let me know

我错过了什么吗?如果您需要更多信息,请告诉我

采纳答案by Lyncean Patel

It seems like your GenericDao not able to convert to IGenericDao and for that, there might be several reasons like is your GenericDao implements the IGenericDao, etc.

似乎您的 GenericDao 无法转换为 IGenericDao,为此,可能有几个原因,例如您的 GenericDao 实现了 IGenericDao 等。

Also the following link might be useful if you are implementing GenericDao pattern:

如果您正在实施 GenericDao 模式,以下链接也可能有用:

https://www.codeproject.com/Articles/251166/The-Generic-DAO-pattern-in-Java-with-Spring-and

https://www.codeproject.com/Articles/251166/The-Generic-DAO-pattern-in-Java-with-Spring-and