org.springframework.beans.factory.BeanCreationException:创建名为“XXX”的bean时出错

时间:2017-06-27 05:56:35

标签: java spring tomcat

我一直在尝试在我的tomcat服务器上部署我的项目,但显然,每次我尝试启动服务器时,都会在我的catalina日志中出现此错误:

Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'mnpTranslationServiceImpl' defined in URL [file:/opt/tomcat/webapps/axis2/WEB-INF/springjdbc.xml]: 
Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'mnpTranslationDAO' of bean class [com.e_horizon.jdbc.mnpTranslation.mnpTranslationServiceImpl]: 
Bean property 'mnpTranslationDAO' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

这是我的bean.xml,我将其命名为springjdbc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">



<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://192.168.XX.X1:3306/msdp" />
    <property name="user" value="root" />
    <property name="password" value="ehorizon" />
    <property name="minPoolSize" value="1" />
    <property name="maxPoolSize" value="500" />
    <property name="numHelperThreads" value="5" />

    <property name="initialPoolSize" value="2" />
    <property name="autoCommitOnClose" value="true" />
    <property name="idleConnectionTestPeriod" value="60" />
    <property name="maxIdleTime" value="1200" />
    <property name="acquireRetryAttempts" value="2" />
</bean>

<bean id="dataSourceHD" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://192.168.XX.X2:3306/hd" />
    <property name="user" value="teligent" />
    <property name="password" value="teligent" />
    <property name="minPoolSize" value="1" />
    <property name="maxPoolSize" value="500" />
    <property name="numHelperThreads" value="5" />

    <property name="initialPoolSize" value="2" />
    <property name="autoCommitOnClose" value="true" />
    <property name="idleConnectionTestPeriod" value="60" />
    <property name="maxIdleTime" value="1200" />
    <property name="acquireRetryAttempts" value="2" />
</bean>

<bean id="mpp2SubscribersDAO" class="com.e_horizon.jdbc.mpp2Subscriber.Mpp2SubscribersDAO">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>

<bean id="mpp2SubscribersService"
    class="com.e_horizon.jdbc.mpp2Subscriber.Mpp2SubscribersServiceImpl">
    <property name="mpp2SubscribersDAO">
        <ref bean="mpp2SubscribersDAO" />
    </property>
</bean>

<bean id="mnpTranslationDAO" class="com.e_horizon.jdbc.mnpTranslation.mnpTranslationDAO">
    <property name="dataSource">
        <ref bean="dataSourceHD" />
    </property>
</bean>

<bean id="mnpTranslationServiceImpl" class="com.e_horizon.jdbc.mnpTranslation.mnpTranslationServiceImpl">
    <property name="mnpTranslationDAO">
        <ref bean="mnpTranslationDAO" />
    </property> 
</bean>

`

这是DAO文件,错误表示不可写:

package com.e_horizon.jdbc.mnpTranslation;

import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;

import com.e_horizon.www.jdbc.common.BaseDAO;

public class mnpTranslationDAO extends BaseDAO {
    private SimpleJdbcInsert jdbcCall;

    public static String TABLE = "MNP_TRANSLATION";
    public static String FIELD_MSISDN = "msisdn";
    public static String FIELD_ROUTING_NUMBER = "routing_number";
    public static String FIELD_LAST_UPDATE = "last_update";
    public static String FIELD_ACTION = "action";

    protected RowMapper getObjectMapper () {
        return new mnpTranslationMapper();
    }

    public void save (mnpTranslation mnp) {
        this.jdbcCall = this.getSimpleJdbcInsert().withTableName(TABLE);
        Map<String, Object> parameters = new HashMap<String, Object>();

        parameters.put(FIELD_MSISDN, mnp.getMsisdn());
        parameters.put(FIELD_ROUTING_NUMBER, mnp.getRouting_number());
        parameters.put(FIELD_LAST_UPDATE, mnp.getLast_update());
        parameters.put(FIELD_ACTION, mnp.getAction());

        jdbcCall.execute(parameters);
    }
}

添加包含setter和getter的模型(mnpTranslation.java):

package com.e_horizon.jdbc.mnpTranslation;

import java.sql.Timestamp;

public class mnpTranslation {
private String msisdn;
private String routing_number;
private Timestamp last_update;
private String action;

    public void setMsisdn (String msisdn) {
        this.msisdn = msisdn;
    }

    public String getMsisdn () {
        return this.msisdn;
    }

    public void setRouting_number (String routing_number) {
        this.routing_number = routing_number;
    }

    public String getRouting_number () {
        return this.routing_number;
    }

    public void setLast_update (Timestamp last_update) {
        this.last_update = last_update;
    }

    public Timestamp getLast_update () {
        return this.last_update;
    }

    public void setAction (String action) {
        this.action = action;
    }

    public String getAction () {
        return this.action;
    }
}

[edit]我正在添加其余的java文件,这样你就可以看到我正在处理的更多内容。非常感谢您查看此内容。

mnpTranslationService.java:

package com.e_horizon.jdbc.mnpTranslation;

public abstract interface mnpTranslationService {
    public abstract void save (mnpTranslation mnp);
}

mnpTranslationServiceImpl.java:

package com.e_horizon.jdbc.mnpTranslation;

public class mnpTranslationServiceImpl {
    private mnpTranslationDAO mnpTranslationDAO;

    public void save (mnpTranslation mnp) {
        this.mnpTranslationDAO.save(mnp);
    }
}

mnpTranslationMapper.java:

package com.e_horizon.jdbc.mnpTranslation;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

public class mnpTranslationMapper implements RowMapper {
    public Object mapRow (ResultSet result, int dex) throws SQLException {
        mnpTranslation mnp = new mnpTranslation();

        mnp.setMsisdn(result.getString("msisdn"));
        mnp.setRouting_number(result.getString("routing_number"));
        mnp.setLast_update(result.getTimestamp("last_update"));
        mnp.setAction(result.getString("action"));

        return mnp;
    }
}

如果您还需要查看其他内容,请与我们联系。我很乐意立刻发布。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

错误消息指出问题出在您的mnpTranslationServiceImpl课程中。

参见错误消息

  

Bean property&#39; mnpTranslationDAO&#39;不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配?

相关问题