Code for spring-servlet configuration - learn spring

Words
150
Reading
1 min
Listen
Play
9y

Hello guys,

this is ravi here

there is spring servlet configuration for spring mvc using eclipse IDE

put inside WEB-INF/config

spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:mvc="http://www.springframework.org/schema/mvc" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xmlns:p="http://www.springframework.org/schema/p" 

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<context:property-placeholder location="classpath:resources/database.properties" />

<context:component-scan base-package="com.blog" />

<tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

<bean id="jspViewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass"

value="org.springframework.web.servlet.view.JstlView" />

<property name="prefix" value="/" />

<property name="suffix" value=".jsp" />

</bean>

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="${database.driver}" />

<property name="url" value="${database.url}" />

<property name="username" value="${database.user}" />

<property name="password" value="${database.password}" />

</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="annotatedClasses">

<list>

<value>com.blog.model.Admin</value>

<value>com.blog.model.Comments</value>

<value>com.blog.model.Feedbacks</value>

<value>com.blog.model.Inquiry</value>

<value>com.blog.model.Likes_Counter</value>

<value>com.blog.model.Posts</value>

<value>com.blog.model.Questions</value>

<value>com.blog.model.Users</value>

</list>

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">${hibernate.dialect}</prop>

<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>

<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>

</props>

</property>

</bean>

<bean id="hibernateTransactionManager"

class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFactory" />

</bean>

</beans>

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 

xmlns="http://java.sun.com/xml/ns/javaee" 

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  

  <servlet>

<servlet-name>spring</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

            <param-name>contextConfigLocation</param-name>

            <param-value>/WEB-INF/config/spring-servlet.xml</param-value>

        </init-param>

        <load-on-startup>1</load-on-startup>

  </servlet>

  

  <servlet-mapping>

<servlet-name>spring</servlet-name>

<url-pattern>/</url-pattern>

  </servlet-mapping>

  <welcome-file-list>

<welcome-file></welcome-file>

  </welcome-file-list>

  

</web-app>

Hope you like this

Code for spring-servlet configuration - learn spring | Ecency