0

我试图创建一个 ParentDao 来处理我的独立 Java 应用程序的所有连接细节。
当我运行我的程序时,我得到下面的错误

线程“主”org.springframework.beans.factory.BeanIsAbstractException 中的异常:创建名为“parentDao”的 bean 时出错:bean 定义是抽象的

我究竟做错了什么?我知道它是一个抽象类,我只是在关注这个也使用抽象类的例子。抽象的 ParentDao 类和这个DRY 你的 Spring Bean我完全迷失了如何在独立应用程序上做到这一点。我在哪里初始化 ApplicationContext 以及如何初始化。

下面是我的连接属性(bean.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="dataSource" destroy-method="close"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@ipaddress:1521:habagat" />
        <property name="username" value="username" />
        <property name="password" value="password" />
    </bean>

    <bean id="parentDao" class="com.mercury.dao.ParentDAO" abstract="true">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="childDao" class="com.mercury.dao.ChildDAOImpl" parent="parentDao"/>        
</beans>

以下是我的主要方法

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext(
        "beans.xml");
ParentDAO parentDao = (ParentDAO) context.getBean("parentDao");
}

和我的父母 DAO 班级

   public abstract class ParentDAO<T> extends JdbcDaoSupport {

        public abstract void insert(T object) throws Exception;

        public abstract void delete(int id) throws Exception;

        public abstract void update(T object) throws Exception;

        public abstract T select(int id) throws Exception;
}

我的服务

public class myService {

    ChildDAO childDao;

    public String getChildrenCount() {


        return int totalCount = childDao.getRecordCount();
    }
}
4

1 回答 1

2

好吧,Parent DAO抽象的。你为什么要尝试把那个bean从上下文中拉出来?你想得到childDao bean。

于 2013-05-09T13:25:26.693 回答