Advertisement
shahdhruvenn

Hibernate Configuration - Spring

Aug 24th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 4.69 KB | None | 0 0
  1. web.xml ::
  2.  
  3.  
  4. <?xml version = "1.0" encoding = "UTF-8"?>
  5. <web-app id="WebApp_ID" version="2.4"
  6.     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
  8.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  9.     <display-name>spring3mvccrawler</display-name>
  10.     <welcome-file-list>
  11.         <welcome-file>index.jsp</welcome-file>
  12.     </welcome-file-list>
  13.     <servlet>
  14.         <servlet-name>crawler</servlet-name>
  15.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  16.         <load-on-startup>1</load-on-startup>
  17.     </servlet>
  18.     <servlet-mapping>
  19.         <servlet-name>crawler</servlet-name>
  20.         <url-pattern>*.html</url-pattern>
  21.     </servlet-mapping>
  22. </web-app>
  23.  
  24.  
  25.  
  26. crawler-servlet.xml (applicationContext.xml)
  27.  
  28.  
  29. <?xml version="1.0" encoding="UTF-8"?>
  30. <beans xmlns="http://www.springframework.org/schema/beans"
  31.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  32.     xmlns:aop="http://www.springframework.org/schema/aop"
  33.     xmlns:context="http://www.springframework.org/schema/context"
  34.     xmlns:jee="http://www.springframework.org/schema/jee"
  35.     xmlns:lang="http://www.springframework.org/schema/lang"
  36.     xmlns:p="http://www.springframework.org/schema/p"
  37.     xmlns:tx="http://www.springframework.org/schema/tx"
  38.     xmlns:util="http://www.springframework.org/schema/util"
  39.     xmlns:mvc="http://www.springframework.org/schema/mvc"
  40.     xsi:schemaLocation="http://www.springframework.org/schema/beans
  41.     http://www.springframework.org/schema/beans/spring-beans.xsd
  42.     http://www.springframework.org/schema/aop
  43.     http://www.springframework.org/schema/aop/spring-aop.xsd
  44.     http://www.springframework.org/schema/context
  45.     http://www.springframework.org/schema/context/spring-context.xsd
  46.     http://www.springframework.org/schema/jee
  47.     http://www.springframework.org/schema/jee/spring-jee.xsd
  48.     http://www.springframework.org/schema/lang
  49.     http://www.springframework.org/schema/lang/spring-lang.xsd
  50.     http://www.springframework.org/schema/tx
  51.     http://www.springframework.org/schema/tx/spring-tx.xsd
  52.     http://www.springframework.org/schema/util
  53.     http://www.springframework.org/schema/util/spring-util.xsd
  54.     http://www.springframework.org/schema/mvc
  55.     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
  56.  
  57.     <context:component-scan base-package="com.digitas.crawler" />
  58.     <context:annotation-config />
  59.         <mvc:annotation-driven/>
  60.     <bean id="viewResolver"
  61.         class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  62.         <property name="prefix">
  63.             <value>/WEB-INF/content/jsp/</value>
  64.         </property>
  65.         <property name="suffix">
  66.             <value>.jsp</value>
  67.         </property>
  68.     </bean>
  69.     <bean id="propertyConfigurer"
  70.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  71.         <property name="location">
  72.             <value>/WEB-INF/jdbc.properties</value>
  73.         </property>
  74.     </bean>
  75.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  76.         <property name="driverClassName">
  77.             <value>${jdbc.driverClassName}</value>
  78.         </property>
  79.         <property name="url">
  80.             <value>${jdbc.databaseurl}</value>
  81.         </property>
  82.         <property name="username">
  83.             <value>${jdbc.username}</value>
  84.         </property>
  85.         <property name="password">
  86.             <value>${jdbc.password}</value>
  87.         </property>
  88.     </bean>
  89.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  90.         <property name="dataSource" ref="dataSource" />
  91.         <property name="configLocation">
  92.             <value>/WEB-INF/hibernate.cfg.xml</value>
  93.         </property>
  94.         <property name="configurationClass">
  95.             <value>org.hibernate.cfg.AnnotationConfiguration</value>
  96.         </property>
  97.         <property name="hibernateProperties">
  98.             <props>
  99.                 <prop key="hibernate.dialect">${jdbc.dialect}</prop>
  100.                 <prop key="hibernate.show_sql">true</prop>
  101.             </props>
  102.         </property>
  103.     </bean>
  104.    
  105.     <bean id="crawlerElementDAO" class =  "com.digitas.crawler.dao.hibernate.impl.CrawlerElementDAOImpl">
  106.         <property name ="batchSize">
  107.             <value>${jdbc.batchSize}</value>
  108.         </property>
  109.     </bean>
  110.    
  111.     <bean id="webClient" class = "com.gargoylesoftware.htmlunit.WebClient"/>
  112.    
  113.     <tx:annotation-driven />
  114.     <bean id="transactionManager"
  115.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  116.         <property name="sessionFactory" ref="sessionFactory" />
  117.     </bean>
  118. </beans>
  119.  
  120.  
  121. hibernate.cfg.xml
  122.  
  123. <?xml version="1.0" encoding="UTF-8"?>
  124. <!DOCTYPE hibernate-configuration PUBLIC
  125.    "-//Hibernate/Hibernate Configuration DTD//EN"
  126.    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  127. <hibernate-configuration>
  128.     <session-factory>
  129.         <mapping class="<YOUR CLASS NAME>" />
  130.         <mapping class="<YOUR CLASS NAME>" />
  131.     </session-factory>
  132. </hibernate-configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement