スタンドアロン Java アプリケーションのすべての接続の詳細を処理する ParentDao を作成しようとしています。
プログラムを実行すると、以下のエラーが表示されます
スレッド「メイン」での例外 org.springframework.beans.factory.BeanIsAbstractException: 名前 'parentDao' の Bean の作成中にエラーが発生しました: Bean 定義が抽象的です
私は何を間違っていますか?私は、抽象クラスも使用したこの例に従っている抽象クラスであることを知っています。抽象 ParentDao クラスとこれは、Spring Bean を DRY します。特に、スタンドアロン アプリケーションでそれを行う方法を完全に失いました。そして、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();
}
}