Advertisement
Guest User

Untitled

a guest
Jun 13th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:p="http://www.springframework.org/schema/p"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  8.  
  9.  
  10. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  11. <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
  12. <property name="url" value="jdbc:mysql://localhost/test"></property>
  13. <property name="username" value="root"></property>
  14. <property name="password" value="root"></property>
  15. </bean>
  16.  
  17. <bean id="mysessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  18. <property name="dataSource" ref="dataSource"></property>
  19.  
  20. <property name="annotatedClasses">
  21. <list>
  22. <value>com.hib.model.MailHib</value>
  23. </list>
  24. </property>
  25.  
  26. <property name="hibernateProperties">
  27. <props>
  28. <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
  29. <prop key="hibernate.hbm2ddl.auto">update</prop>
  30. <prop key="hibernate.show_sql">true</prop>
  31.  
  32. </props>
  33. </property>
  34. </bean>
  35.  
  36. <bean id="template" class="org.springframework.orm.hibernate3.HibernateTemplate">
  37. <property name="sessionFactory" ref="mysessionFactory"></property>
  38. </bean>
  39.  
  40. <bean id="d" class="com.dao.MailDaoCls">
  41. <property name="template" ref="template"></property>
  42. </bean>
  43.  
  44.  
  45. </beans>
  46.  
  47. package com.dao;
  48.  
  49. import org.springframework.orm.hibernate3.HibernateTemplate;
  50.  
  51. import com.bo.model.Mail;
  52. import com.hib.model.MailHib;
  53.  
  54. public class MailDaoCls {
  55. HibernateTemplate template;
  56. public void setTemplate(HibernateTemplate template) {
  57. this.template = template;
  58. }
  59. //method to save employee
  60. public void saveEmployee(MailHib e){
  61. template.save(e);
  62. }
  63.  
  64. }
  65.  
  66. Resource r=new ClassPathResource("applicationContext.xml");
  67. BeanFactory factory=new XmlBeanFactory(r);
  68.  
  69. MailDaoCls dao=(MailDaoCls)factory.getBean("d");
  70.  
  71. MailHib mail = new MailHib();
  72. //mail.setMailId(1);
  73. mail.setFrmEMail("ffff");
  74. mail.setToEMail("ssss");
  75. mail.setSubjectEMail("fffffsf");
  76. mail.setMessage("messagssse");
  77. dao.saveEmployee(mail);
  78.  
  79. Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'd' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'template' while setting bean property 'template'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'template' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'mysessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mysessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'dataSource' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource[![enter image description here][1]][1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement