简体   繁体   English

Bean定义是独立Java应用程序上的抽象错误

[英]Bean definition is abstract Error on a Standalone Java application

Im trying to create a ParentDao that will handle all the connection details for my Standalone Java application. 我试图创建一个ParentDao,它将处理我的独立Java应用程序的所有连接细节。
When I run my program I get the Error below 当我运行我的程序时,我得到下面的错误

Exception in thread "main" org.springframework.beans.factory.BeanIsAbstractException: Error creating bean with name 'parentDao': Bean definition is abstract 线程“main”中的异常org.springframework.beans.factory.BeanIsAbstractException:创建名为'parentDao'的bean时出错:Bean定义是抽象的

What am I doing wrong? 我究竟做错了什么? I know its an abstract class I was just following this examples which also used abstract classes. 我知道它是一个抽象类我只是遵循这个也使用抽象类的例子。 abstract ParentDao Class and this one DRY your Spring Bean Im totally lost specially on how to do it on a Standalone application. 抽象的ParentDao类和这一个干你的Spring Bean我完全失去了如何在独立应用程序上执行它。 And where do I initialize the ApplicationContext and how. 我在哪里初始化ApplicationContext以及如何。

Below is my Connection Properties (bean.xml) 下面是我的连接属性(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>

BELOW IS MY MAIN METHOD 以下是我的主要方法

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

AND MY PARENT DAO CLASS 和我的父母DAO CLASS

   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;
}

MY SERVICE 我的服务

public class myService {

    ChildDAO childDao;

    public String getChildrenCount() {


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

Well, the Parent DAO is abstract. 那么,父DAO 抽象的。 Why would you try to pull that bean out of the context? 你为什么要试着把豆子拉出来? You want to get the childDao bean. 你想得到childDao bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM