Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sep 04, 2018 12:06:40 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
- INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3eb07fd3: startup date [Tue Sep 04 00:06:40 IST 2018]; root of context hierarchy
- Sep 04, 2018 12:06:40 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
- INFO: Loading XML bean definitions from class path resource [com/anish/spring/springorm1/product/test/config.xml]
- Sep 04, 2018 12:06:40 AM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
- INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
- Sep 04, 2018 12:06:41 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
- WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productDao': Unsatisfied dependency expressed through field 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Failed to introspect bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
- Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'productDao': Unsatisfied dependency expressed through field 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Failed to introspect bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
- at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
- at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
- at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
- at com.anish.spring.springorm1.product.test.Test.main(Test.java:13)
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Failed to introspect bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1118)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1091)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:923)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:804)
- at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:558)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
- at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1260)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
- ... 15 more
- Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
- at java.lang.Class.getDeclaredMethods0(Native Method)
- at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
- at java.lang.Class.getDeclaredMethods(Unknown Source)
- at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
- at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
- at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
- ... 27 more
- Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
- at java.net.URLClassLoader.findClass(Unknown Source)
- at java.lang.ClassLoader.loadClass(Unknown Source)
- at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
- at java.lang.ClassLoader.loadClass(Unknown Source)
- ... 34 more
- <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>com.anish.spring</groupId>
- <artifactId>springorm1</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>springorm1</name>
- <url>http://maven.apache.org</url>
- <properties>
- <springframework.version>4.3.6.RELEASE</springframework.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${springframework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${springframework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-orm</artifactId>
- <version>${springframework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>5.2.5.Final</version>
- </dependency>
- <dependency>
- <groupId>postgresql</groupId>
- <artifactId>postgresql</artifactId>
- <version>9.1-901-1.jdbc4</version>
- </dependency>
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- <version>1.0.0.GA</version>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-validator</artifactId>
- <version>4.0.2.GA</version>
- </dependency>
- </dependencies>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- </project>
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
- xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx.xsd">
- <tx:annotation-driven />
- <context:component-scan base-package="com.anish.spring.springorm1.product.dao.impl" />
- <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
- name="dataSource" p:url="jdbc:postgresql://localhost:5432/spring"
- p:driverClassName="org.postgresql.Driver" p:username="postgres"
- p:password="system" />
- <bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
- name="sessionFactory" p:dataSource-ref="dataSource">
- <property name="hibernateProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
- <prop key="hibernate.show_sql">true</prop>
- </props>
- </property>
- <property name="annotatedClasses">
- <list>
- <value>com.anish.spring.springorm1.product.entity.Product</value>
- </list>
- </property>
- </bean>
- <bean class="org.springframework.orm.hibernate5.HibernateTemplate"
- name="hibernateTemplate" p:sessionFactory-ref="sessionFactory" />
- <bean class="org.springframework.orm.hibernate5.HibernateTransactionManager"
- name="transactionManager" p:sessionFactory-ref="sessionFactory" />
- </beans>
- package com.anish.spring.springorm1.product.dao;
- import com.anish.spring.springorm1.product.entity.Product;
- public interface ProductDao {
- int create(Product product);
- }
- package com.anish.spring.springorm1.product.dao.impl;
- import java.io.Serializable;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.orm.hibernate5.HibernateTemplate;
- import org.springframework.stereotype.Component;
- import org.springframework.transaction.annotation.Transactional;
- import com.anish.spring.springorm1.product.dao.ProductDao;
- import com.anish.spring.springorm1.product.entity.Product;
- @Component
- public class ProductDaoImpl implements ProductDao {
- @Autowired
- HibernateTemplate hibernateTemplate;
- @Override
- @Transactional
- public int create(Product product) {
- Integer result = (Integer) hibernateTemplate.save(product);
- return result;
- }
- }
- package com.anish.spring.springorm1.product.entity;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- import javax.persistence.Table;
- import javax.persistence.Column;
- @Entity
- @Table(name="product")
- public class Product {
- @Id
- @Column(name="id")
- private int id;
- @Column(name="name")
- private String name;
- @Column(name="description")
- private String desc;
- @Column(name="price")
- private double price;
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getDesc() {
- return desc;
- }
- public void setDesc(String desc) {
- this.desc = desc;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- }
- package com.anish.spring.springorm1.product.test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.anish.spring.springorm1.product.dao.ProductDao;
- import com.anish.spring.springorm1.product.entity.Product;
- public class Test {
- public static void main(String[] args) {
- ApplicationContext context = new ClassPathXmlApplicationContext(
- "com/anish/spring/springorm1/product/test/config.xml");
- ProductDao bean = (ProductDao) context.getBean("productDaoImpl");
- Product product = new Product();
- product.setId(1);
- product.setName("Iphone");
- product.setDesc("Its Good");
- product.setPrice(21000.0);
- bean.create(product);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement