Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't' defined in class path resource [resources/spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  2. Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't' defined in class path resource [resources/spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  3. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1568)
  4. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
  5. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
  6. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
  7. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  8. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  9. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  10. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  11. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
  12. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
  13. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
  14. at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
  15. at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
  16. at test.Client.main(Client.java:10)
  17. Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'driver' of bean class [beans.Test]: Bean property 'driver' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  18. at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)
  19. at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:437)
  20. at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:292)
  21. at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
  22. at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
  23. at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
  24. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1564)
  25. ... 13 more
  26.  
  27. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
  28. "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
  29.  
  30. <beans>
  31.  
  32. <bean id="t" class="beans.Test">
  33.  
  34. <property name="driver" value="com.mysql.jdbc.Driver"/>
  35. <property name="url" value="jdbc:mysql://localhost/emp"/>
  36. <property name="user" value="root"/>
  37. <property name="password" value="root123"/>
  38.  
  39. </bean>
  40.  
  41. </beans>
  42.  
  43. package beans;
  44.  
  45. import java.sql.Connection;
  46. import java.sql.DriverManager;
  47. import java.sql.PreparedStatement;
  48.  
  49. import org.springframework.beans.factory.DisposableBean;
  50. import org.springframework.beans.factory.InitializingBean;
  51.  
  52. public class Test implements InitializingBean, DisposableBean
  53. {
  54. private String driver,url,user,password;
  55. private Connection con;
  56.  
  57. public void setDriver(String driver) {
  58. this.driver = driver;
  59. }
  60. public void setUrl(String url) {
  61. this.url = url;
  62. }
  63. public void setUser(String user) {
  64. this.user = user;
  65. }
  66. public void setPassword(String password) {
  67. this.password = password;
  68. }
  69.  
  70. @Override
  71. public void afterPropertiesSet() throws Exception
  72. {
  73. Class.forName(driver);
  74. con= DriverManager.getConnection(url, user, password);
  75. System.out.println("Connection Opened");
  76. }
  77.  
  78. public void insert(int id,int age, String first, String last )throws Exception
  79. {
  80. PreparedStatement ps=con.prepareStatement("insert into employee vvalues(?,?,?,?)");
  81. ps.setInt(1, id);
  82. ps.setInt(2, age);
  83. ps.setString(3, first);
  84. ps.setString(4, last);
  85. ps.executeUpdate();
  86. System.out.println("Successfully Inserted");
  87.  
  88. }
  89.  
  90. @Override
  91. public void destroy() throws Exception
  92. {
  93. con.close();
  94. System.out.println("Connection Closed");
  95. }
  96.  
  97. }
  98.  
  99. package test;
  100.  
  101. import org.springframework.context.ConfigurableApplicationContext;
  102. import org.springframework.context.support.ClassPathXmlApplicationContext;
  103.  
  104. public class Client
  105. {
  106. public static void main(String[] args)
  107. {
  108. ConfigurableApplicationContext cap=new ClassPathXmlApplicationContext("resources/spring.xml");
  109.  
  110. }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement