Exception in thread "main" java.lang.ClassCastException: org.apache.commons.dbcp.Basi
tout est dans le titre.
config.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<?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-2.5.xsd">
<bean id="dao" class="mis.cinq.dao.DaoJdbc" />
<bean id="service" class="mis.cinq.service.ServiceSpringJdbc">
<property name="dao" ref="dao" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/gestcar" />
<property name="username" value="jpa" />
<property name="password" value="jpa" />
</bean>
</beans> |
code java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| BasicConfigurator.configure();
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring_config_jdbc.xml");
BeanFactory factory = applicationContext;
logger.info("LittleLeagueServices Initializing");
DriverManagerDataSource ds = (DriverManagerDataSource) factory.getBean("dataSource");
IDaoSpringJdbc dao = (IDaoSpringJdbc) factory.getBean("dao");
dao.setDataSource(ds);
IService service = (IService) factory.getBean("service");
logger.info("service Initialized");
logger.info("service: Retrieving Nature");
List nature = service.getAllNatures();
for(int i = 0; i < nature.size(); i++){
Nature n = (Nature)nature.get(i);
logger.info(n.toString());
} |
l'erreur à la ligne
Code:
1 2
|
DriverManagerDataSource ds = (DriverManagerDataSource) factory.getBean("dataSource"); |