Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.87 KB | None | 0 0
  1. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'siteController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.mycompany.web_shop.model.AllproductsDao com.mycompany.web_shop.controller.SiteController.allproductsDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'allproductsDao' defined in ServletContext resource [/WEB-INF/spring-database.xml]: Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
  2.  
  3. <beans 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. xmlns:aop="http://www.springframework.org/schema/aop"
  7. xmlns:tx="http://www.springframework.org/schema/tx"
  8. xmlns:mvc="http://www.springframework.org/schema/mvc"
  9. xmlns:context="http://www.springframework.org/schema/context"
  10. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  11. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  12. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  13. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  14. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  15.  
  16.  
  17. <bean id="propertyConfigurer"
  18. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  19. p:location="/WEB-INF/jdbc.properties" />
  20.  
  21. <bean id="dataSource"
  22. class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  23. p:driverClassName="${jdbc.driverClassName}"
  24. p:url="${jdbc.url}"
  25. p:username="${jdbc.username}"
  26. p:password="${jdbc.password}" />
  27.  
  28. <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  29. <property name="dataSource" ref="dataSource" />
  30. <property name="annotatedClasses">
  31. <list>
  32. <value>com.mycompany.web_shop.model.Allproducts</value>
  33. </list>
  34. </property>
  35. <property name="hibernateProperties">
  36. <props>
  37. <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
  38. <prop key="hibernate.current_session_context_class">thread</prop>
  39. </props>
  40. </property>
  41. </bean>
  42.  
  43.  
  44.  
  45. <bean id = "allproductsDao" class="com.mycompany.web_shop.model.AllproductsDao">
  46. </bean>
  47.  
  48. <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
  49.  
  50.  
  51. </beans>
  52.  
  53. <beans xmlns="http://www.springframework.org/schema/beans"
  54. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  55. xmlns:p="http://www.springframework.org/schema/p"
  56. xmlns:aop="http://www.springframework.org/schema/aop"
  57. xmlns:tx="http://www.springframework.org/schema/tx"
  58. xmlns:mvc="http://www.springframework.org/schema/mvc"
  59. xmlns:context="http://www.springframework.org/schema/context"
  60. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  61. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
  62. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  63. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
  64. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  65.  
  66.  
  67. <mvc:annotation-driven/>
  68. <context:component-scan base-package="com.mycompany.web_shop.controller"/>
  69. <context:component-scan base-package="com.mycompany.web_shop.model"/>
  70. <mvc:resources mapping="/resources/**" location="/resources/"/>
  71.  
  72. <!--bean id="propertyConfigurer"
  73. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
  74. p:location="/WEB-INF/jdbc.properties" />
  75.  
  76. <bean id="dataSource"
  77. class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  78. p:driverClassName="${jdbc.driverClassName}"
  79. p:url="${jdbc.url}"
  80. p:username="${jdbc.username}"
  81. p:password="${jdbc.password}" /-->
  82.  
  83. <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
  84.  
  85. </beans>
  86.  
  87. package com.mycompany.web_shop.model;
  88.  
  89. import java.util.List;
  90. import org.hibernate.Session;
  91. import org.hibernate.SessionFactory;
  92. import org.springframework.beans.factory.annotation.Autowired;
  93. import org.springframework.stereotype.Component;
  94.  
  95. //@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
  96. @Component
  97. public class AllproductsDao {
  98.  
  99. @Autowired
  100. SessionFactory sessionFactory;
  101.  
  102. public List<Allproducts> find() {
  103. Session session = sessionFactory.getCurrentSession();
  104. session.beginTransaction();
  105. List<Allproducts> result = session.createCriteria(Allproducts.class).list();
  106. session.getTransaction().commit();
  107. return result;
  108. }
  109. }
  110.  
  111. package com.mycompany.web_shop.controller;
  112.  
  113.  
  114. import com.mycompany.web_shop.model.Allproducts;
  115. import com.mycompany.web_shop.model.AllproductsDao;
  116. import java.util.List;
  117. import org.springframework.beans.factory.annotation.Autowired;
  118. import org.springframework.stereotype.Controller;
  119. import org.springframework.web.bind.annotation.RequestMapping;
  120. import org.springframework.ui.ModelMap;
  121.  
  122. @Controller
  123. public class SiteController {
  124.  
  125.  
  126. @Autowired
  127. AllproductsDao allproductsDao;
  128.  
  129.  
  130. @RequestMapping("/")
  131. public String index(ModelMap model) {
  132.  
  133. List<Allproducts> products = allproductsDao.find();
  134.  
  135. model.addAttribute("products", products);
  136.  
  137. return "index";
  138. }
  139.  
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement