gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:02:36 25 4
gpt4 key购买 nike

我正在尝试创建一个 ParentDao 来处理我的独立 Java 应用程序的所有连接详细信息。
当我运行我的程序时,出现以下错误

Exception in thread "main" org.springframework.beans.factory.BeanIsAbstractException: Error creating bean with name 'parentDao': Bean definition is abstract

我做错了什么?我知道它是一个抽象类,我只是在遵循这个也使用抽象类的示例。 abstract ParentDao Class还有这个DRY your 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");
}

和我的 parent 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();
}
}

最佳答案

嗯,Parent DAO 抽象的。你为什么要尝试从上下文中提取该 bean?您想要获取 childDao bean。

关于java - Bean 定义是抽象的 独立 Java 应用程序上的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16462672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com