Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
- <bean id="propertyConfigurer"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
- p:location="/WEB-INF/jdbc.properties" />
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource"
- p:driverClassName="${jdbc.driverClassName}"
- p:url="${jdbc.url}"
- p:username="${jdbc.username}"
- p:password="${jdbc.password}" />
- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="annotatedClasses">
- <list>
- <value>com.mycompany.web_shop.model.Allproducts</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
- <prop key="hibernate.current_session_context_class">thread</prop>
- </props>
- </property>
- </bean>
- <bean id = "allproductsDao" class="com.mycompany.web_shop.model.AllproductsDao">
- </bean>
- <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
- </beans>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
- <mvc:annotation-driven/>
- <context:component-scan base-package="com.mycompany.web_shop.controller"/>
- <context:component-scan base-package="com.mycompany.web_shop.model"/>
- <mvc:resources mapping="/resources/**" location="/resources/"/>
- <!--bean id="propertyConfigurer"
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
- p:location="/WEB-INF/jdbc.properties" />
- <bean id="dataSource"
- class="org.springframework.jdbc.datasource.DriverManagerDataSource"
- p:driverClassName="${jdbc.driverClassName}"
- p:url="${jdbc.url}"
- p:username="${jdbc.username}"
- p:password="${jdbc.password}" /-->
- <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
- </beans>
- package com.mycompany.web_shop.model;
- import java.util.List;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- //@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
- @Component
- public class AllproductsDao {
- @Autowired
- SessionFactory sessionFactory;
- public List<Allproducts> find() {
- Session session = sessionFactory.getCurrentSession();
- session.beginTransaction();
- List<Allproducts> result = session.createCriteria(Allproducts.class).list();
- session.getTransaction().commit();
- return result;
- }
- }
- package com.mycompany.web_shop.controller;
- import com.mycompany.web_shop.model.Allproducts;
- import com.mycompany.web_shop.model.AllproductsDao;
- import java.util.List;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.ui.ModelMap;
- @Controller
- public class SiteController {
- @Autowired
- AllproductsDao allproductsDao;
- @RequestMapping("/")
- public String index(ModelMap model) {
- List<Allproducts> products = allproductsDao.find();
- model.addAttribute("products", products);
- return "index";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement