Dabord merci d'éssayer de m'aider.
J'ai commencé a étudier Spring Jdbc je souhaite faire tourner un exemple
j'utilise Maven donc je vous soumets le Pom et l'erreur provonant de la console ainsi que mon main.
Et pour finir le beans.xml
Derby est bien lancé et configuré et la table vehicule est paramétrée et opérationnel.
Voici l'erreur que j'ai dans la console eclipse
Voici mon fichier Pom.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 11 oct. 2010 01:56:26 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@33dff3a2: startup date [Mon Oct 11 01:56:26 CEST 2010]; root of context hierarchy 11 oct. 2010 01:56:26 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [beans.xml] 11 oct. 2010 01:56:26 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@ac44b88: defining beans [dataSource,vehicleDao,vehicleInsertOperation,vehicleQueryOperation,vehicleCountOperation]; root of factory hierarchy 11 oct. 2010 01:56:27 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@ac44b88: defining beans [dataSource,vehicleDao,vehicleInsertOperation,vehicleQueryOperation,vehicleCountOperation]; root of factory hierarchy Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [beans.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'initialsize' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'initialsize' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1361) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.apress.springrecipes.vehicle.Main.main(Main.java:10) Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'initialsize' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'initialsize' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1038) at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:914) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76) at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1358) ... 13 more
et voici ma class main
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>SpringJdbc</groupId> <artifactId>SpringJdbc</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>3.0.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.0.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6.SEC02</version> </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <version>10.6.1.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>3.0.4.RELEASE</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>20030825.184428</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>20030825.183949</version> </dependency> </dependencies> </project>
et voici le fichier de configuration beans.xml pour Spring
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.apress.springrecipes.vehicle; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); VehicleDao vehicleDao = (VehicleDao) context.getBean("vehicleDao"); Vehicle vehicle = new Vehicle("EX0001", "Vert", 4, 4); vehicleDao.insert(vehicle); } }
donc c'est le code d'exemple d'un bouquin il y a quelque chose qui m'échappe.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <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="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/> <property name="url" value="jdbc:derby://localhost:1527/VEHICULE;create=true" /> <property name="username" value="app" /> <property name="password" value="app" /> <!-- <property name="initialsize" value="2" /> <property name="maxactive" value="4" /> --> </bean> <bean id="vehicleDao" class="com.apress.springrecipes.vehicle.JdbcVehicleDao"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="vehicleInsertOperation" class="com.apress.springrecipes.vehicle.VehicleInsertOperation"> <constructor-arg ref="dataSource" /> </bean> <bean id="vehicleQueryOperation" class="com.apress.springrecipes.vehicle.VehicleQueryOperation"> <constructor-arg ref="dataSource" /> </bean> <bean id="vehicleCountOperation" class="com.apress.springrecipes.vehicle.VehicleCountOperation"> <constructor-arg ref="dataSource" /> </bean> </beans>
merci d'avance pour votre aide
Partager