简体   繁体   中英

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.
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

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. And where do I initialize the ApplicationContext and how.

Below is my Connection Properties (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

   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. Why would you try to pull that bean out of the context? You want to get the childDao bean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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