Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.33 KB | None | 0 0
  1. Sep 04, 2018 12:06:40 AM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
  2. INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@3eb07fd3: startup date [Tue Sep 04 00:06:40 IST 2018]; root of context hierarchy
  3. Sep 04, 2018 12:06:40 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  4. INFO: Loading XML bean definitions from class path resource [com/anish/spring/springorm1/product/test/config.xml]
  5. Sep 04, 2018 12:06:40 AM org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor <init>
  6. INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  7. Sep 04, 2018 12:06:41 AM org.springframework.context.support.ClassPathXmlApplicationContext refresh
  8. 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
  9. 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
  10. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
  11. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  12. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
  13. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
  14. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
  15. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
  16. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  17. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  18. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  19. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  20. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
  21. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
  22. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
  23. at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
  24. at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
  25. at com.anish.spring.springorm1.product.test.Test.main(Test.java:13)
  26. 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
  27. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)
  28. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1118)
  29. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1091)
  30. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:923)
  31. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:804)
  32. at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:558)
  33. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
  34. at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:403)
  35. at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:220)
  36. at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1260)
  37. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
  38. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
  39. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
  40. ... 15 more
  41. Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
  42. at java.lang.Class.getDeclaredMethods0(Native Method)
  43. at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
  44. at java.lang.Class.getDeclaredMethods(Unknown Source)
  45. at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
  46. at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
  47. at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
  48. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
  49. ... 27 more
  50. Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
  51. at java.net.URLClassLoader.findClass(Unknown Source)
  52. at java.lang.ClassLoader.loadClass(Unknown Source)
  53. at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
  54. at java.lang.ClassLoader.loadClass(Unknown Source)
  55. ... 34 more
  56.  
  57. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  59. <modelVersion>4.0.0</modelVersion>
  60.  
  61. <groupId>com.anish.spring</groupId>
  62. <artifactId>springorm1</artifactId>
  63. <version>0.0.1-SNAPSHOT</version>
  64. <packaging>jar</packaging>
  65.  
  66. <name>springorm1</name>
  67. <url>http://maven.apache.org</url>
  68.  
  69. <properties>
  70. <springframework.version>4.3.6.RELEASE</springframework.version>
  71. </properties>
  72.  
  73. <dependencies>
  74. <dependency>
  75. <groupId>org.springframework</groupId>
  76. <artifactId>spring-core</artifactId>
  77. <version>${springframework.version}</version>
  78. </dependency>
  79. <dependency>
  80. <groupId>org.springframework</groupId>
  81. <artifactId>spring-context</artifactId>
  82. <version>${springframework.version}</version>
  83. </dependency>
  84. <dependency>
  85. <groupId>org.springframework</groupId>
  86. <artifactId>spring-orm</artifactId>
  87. <version>${springframework.version}</version>
  88. </dependency>
  89. <dependency>
  90. <groupId>org.hibernate</groupId>
  91. <artifactId>hibernate-core</artifactId>
  92. <version>5.2.5.Final</version>
  93. </dependency>
  94. <dependency>
  95. <groupId>postgresql</groupId>
  96. <artifactId>postgresql</artifactId>
  97. <version>9.1-901-1.jdbc4</version>
  98. </dependency>
  99. <dependency>
  100. <groupId>javax.validation</groupId>
  101. <artifactId>validation-api</artifactId>
  102. <version>1.0.0.GA</version>
  103. </dependency>
  104. <dependency>
  105. <groupId>org.hibernate</groupId>
  106. <artifactId>hibernate-validator</artifactId>
  107. <version>4.0.2.GA</version>
  108. </dependency>
  109. </dependencies>
  110. <build>
  111. <pluginManagement>
  112. <plugins>
  113. <plugin>
  114. <groupId>org.apache.maven.plugins</groupId>
  115. <artifactId>maven-compiler-plugin</artifactId>
  116. <version>3.2</version>
  117. <configuration>
  118. <source>1.7</source>
  119. <target>1.7</target>
  120. </configuration>
  121. </plugin>
  122. </plugins>
  123. </pluginManagement>
  124. </build>
  125. </project>
  126.  
  127. <?xml version="1.0" encoding="UTF-8"?>
  128. <beans xmlns="http://www.springframework.org/schema/beans"
  129. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  130. xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
  131. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
  132. xsi:schemaLocation="http://www.springframework.org/schema/beans
  133. http://www.springframework.org/schema/beans/spring-beans.xsd
  134. http://www.springframework.org/schema/context
  135. http://www.springframework.org/schema/context/spring-context.xsd
  136. http://www.springframework.org/schema/util
  137. http://www.springframework.org/schema/util/spring-util.xsd
  138. http://www.springframework.org/schema/tx
  139. http://www.springframework.org/schema/tx/spring-tx.xsd">
  140.  
  141. <tx:annotation-driven />
  142.  
  143. <context:component-scan base-package="com.anish.spring.springorm1.product.dao.impl" />
  144. <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  145. name="dataSource" p:url="jdbc:postgresql://localhost:5432/spring"
  146. p:driverClassName="org.postgresql.Driver" p:username="postgres"
  147. p:password="system" />
  148. <bean class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
  149. name="sessionFactory" p:dataSource-ref="dataSource">
  150.  
  151. <property name="hibernateProperties">
  152. <props>
  153. <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL82Dialect</prop>
  154. <prop key="hibernate.show_sql">true</prop>
  155. </props>
  156. </property>
  157. <property name="annotatedClasses">
  158. <list>
  159. <value>com.anish.spring.springorm1.product.entity.Product</value>
  160. </list>
  161. </property>
  162. </bean>
  163.  
  164. <bean class="org.springframework.orm.hibernate5.HibernateTemplate"
  165. name="hibernateTemplate" p:sessionFactory-ref="sessionFactory" />
  166. <bean class="org.springframework.orm.hibernate5.HibernateTransactionManager"
  167. name="transactionManager" p:sessionFactory-ref="sessionFactory" />
  168.  
  169. </beans>
  170.  
  171. package com.anish.spring.springorm1.product.dao;
  172.  
  173. import com.anish.spring.springorm1.product.entity.Product;
  174.  
  175. public interface ProductDao {
  176.  
  177. int create(Product product);
  178. }
  179.  
  180. package com.anish.spring.springorm1.product.dao.impl;
  181.  
  182. import java.io.Serializable;
  183.  
  184. import org.springframework.beans.factory.annotation.Autowired;
  185. import org.springframework.orm.hibernate5.HibernateTemplate;
  186. import org.springframework.stereotype.Component;
  187. import org.springframework.transaction.annotation.Transactional;
  188.  
  189. import com.anish.spring.springorm1.product.dao.ProductDao;
  190. import com.anish.spring.springorm1.product.entity.Product;
  191.  
  192. @Component
  193. public class ProductDaoImpl implements ProductDao {
  194.  
  195. @Autowired
  196. HibernateTemplate hibernateTemplate;
  197. @Override
  198. @Transactional
  199. public int create(Product product) {
  200. Integer result = (Integer) hibernateTemplate.save(product);
  201. return result;
  202. }
  203.  
  204. }
  205.  
  206. package com.anish.spring.springorm1.product.entity;
  207.  
  208. import javax.persistence.Entity;
  209. import javax.persistence.Id;
  210. import javax.persistence.Table;
  211. import javax.persistence.Column;
  212.  
  213. @Entity
  214. @Table(name="product")
  215. public class Product {
  216. @Id
  217. @Column(name="id")
  218. private int id;
  219. @Column(name="name")
  220. private String name;
  221. @Column(name="description")
  222. private String desc;
  223. @Column(name="price")
  224. private double price;
  225.  
  226. public int getId() {
  227. return id;
  228. }
  229.  
  230. public void setId(int id) {
  231. this.id = id;
  232. }
  233.  
  234. public String getName() {
  235. return name;
  236. }
  237.  
  238. public void setName(String name) {
  239. this.name = name;
  240. }
  241.  
  242. public String getDesc() {
  243. return desc;
  244. }
  245.  
  246. public void setDesc(String desc) {
  247. this.desc = desc;
  248. }
  249.  
  250. public double getPrice() {
  251. return price;
  252. }
  253.  
  254. public void setPrice(double price) {
  255. this.price = price;
  256. }
  257.  
  258. }
  259.  
  260. package com.anish.spring.springorm1.product.test;
  261.  
  262. import org.springframework.context.ApplicationContext;
  263. import org.springframework.context.support.ClassPathXmlApplicationContext;
  264.  
  265. import com.anish.spring.springorm1.product.dao.ProductDao;
  266. import com.anish.spring.springorm1.product.entity.Product;
  267.  
  268. public class Test {
  269.  
  270. public static void main(String[] args) {
  271.  
  272. ApplicationContext context = new ClassPathXmlApplicationContext(
  273. "com/anish/spring/springorm1/product/test/config.xml");
  274. ProductDao bean = (ProductDao) context.getBean("productDaoImpl");
  275. Product product = new Product();
  276. product.setId(1);
  277. product.setName("Iphone");
  278. product.setDesc("Its Good");
  279. product.setPrice(21000.0);
  280. bean.create(product);
  281. }
  282.  
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement