talha06 0 Newbie Poster

Hello to everyone,

I'm trying to setup a Spring MVC project. I posted my configuration files below.
I'll be really glad if someone helps me.

Thanks in advance,
With regards,
Talha.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
	<display-name>local</display-name>
  
	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>webapp.root</param-value>
	</context-param>
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>/WEB-INF/log4j.xml</param-value>
	</context-param>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
    		/WEB-INF/applicationContext.xml</param-value>
	</context-param>
	
 	<listener>
    	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 	 </listener>    
    
	<servlet>
		<servlet-name>webmvc</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>
				/WEB-INF/webmvc-servlet.xml
			</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
  
	<servlet-mapping>
		<servlet-name>webmvc</servlet-name>
		<url-pattern>*.*</url-pattern>
	</servlet-mapping>

	<session-config> 
		<session-timeout>30</session-timeout> 
	</session-config> 

	<filter>
		<filter-name>encoding-filter</filter-name>
		<filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
		</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param> 
			<param-name>forceEncoding</param-name> 
			<param-value>true</param-value> 
		</init-param> 
	</filter>

	<filter-mapping>
		<filter-name>encoding-filter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
    
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>jsp/index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>jsp/default.jsp</welcome-file>
		<welcome-file>login.html</welcome-file>
		<welcome-file>login.htm</welcome-file>
		<welcome-file>jsp/login.jsp</welcome-file>
	</welcome-file-list>
  
	<error-page>
		<error-code>404</error-code>
		<location>/404.jsp</location>
	</error-page>
	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/error.jsp</location>
	</error-page>
 
</web-app>

webmvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
 	
 	<bean id="localControllerMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver">
		<property name="prefix" value="hnd_"/>
	</bean>
	
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass"> 
			<value>org.springframework.web.servlet.view.JstlView</value>
		</property>	
		<property name="prefix"> 
			<value>/WEB-INF/jsp/</value>
		</property>
		<property name="suffix"> 
			<value>".jsp"</value>
		</property>
	</bean>
	
	<bean id="localController" class="view.LocalVIEW">
		<property name="methodNameResolver">
			<ref local="localControllerMethodNameResolver"/>
		</property>
		<property name="localBUS">
			<ref bean="localBUS"/>
		</property>
	</bean>
	
	<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
		<property name="mappings">
			<props>
				<prop key="/*.htm">localController</prop>
				<prop key="/*.html">localController</prop>
				<prop key="/*.jsp">localController</prop>
				<prop key="/*.ajax">localController</prop>
			</props>
		</property>
	</bean>
  
	<bean id="localBUS" class="bus.LocalBUS">
	</bean>
	
</beans>

applicationContext.xml

<?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:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
	
	<bean id="txProxyTemplate" abstract="true"	class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
		<property name="transactionManager">
			<ref local="transactionManager" />
		</property>
		<property name="transactionAttributes">
			<props>
				<prop key="list*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="get*">PROPAGATION_REQUIRED, readOnly</prop>
				<prop key="*">	PROPAGATION_REQUIRED, -MVARollbackException,+MVANoRollbackException	</prop>
			</props>
		</property>
	</bean>
	

	<bean id="contextApplicationContextProvider" class="context.ApplicationContextProvider"/>  
	<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
	
	<bean id="transactionManager"
		class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory">
			<ref local="baseSessionFactory" />
		</property>
	</bean>
	<!-- BUSINESS TARGET PRIMARY BUSINESS OBJECT: Hibernate implementation -->
	
	<bean id="localBUS" parent="txProxyTemplate" >
		<property name="target">
			<ref local="targetLocalBUS" />
		</property>
	</bean>
	
	
	<bean id="targetLocalBUS" class="bus.LocalBUS">
		<property name="localDAO">
			<ref local="local1DAO" />
		</property>
	</bean>
	
	<bean id="hibernateConfiguration"
		factory-bean="&amp;baseSessionFactory"
		factory-method="getConfiguration" />

	

	<bean id="local1DAO" class="dao.LocalDAO" >
		<property name="sessionFactory">
			<ref local="baseSessionFactory" />
		</property>
	</bean>
	
	<bean id="baseSessionFactory"
		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
				<prop key="hibernate.show_sql">false</prop>
			</props>
		</property>
	</bean>

	
	<bean id="propPlaceholderConfigurer" class="advice.PropResolver" init-method="init">
		<property name="locationsMap">
			<props>
				<prop key="prod">/WEB-INF/prod.properties</prop>
			</props>
		</property>
		<property name="ignoreUnresolvablePlaceholders" value="true"/>
	</bean>
	
	<bean id="dataSource"	class="com.mchange.v2.c3p0.ComboPooledDataSource"	destroy-method="close">
		<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
		<property name="jdbcUrl">		
			<value>jdbc:oracle:thin:@${database.url}</value>
		</property>
		<property name="properties">
			<props>
				<prop key="user">${database.user}</prop>
				<prop key="password">${database.password}</prop>
			</props>
		</property>
		<property name="maxPoolSize" value="50"/>
		<property name="initialPoolSize" value="2"/>
		<property name="minPoolSize" value="1"/>
		<property name="maxStatements" value="200"/>
		<property name="maxIdleTime" value="300"/>
		<property name="acquireIncrement"  value="10"/>
		<property name="unreturnedConnectionTimeout" value="90"/>
		<property name="maxConnectionAge" value="120"/>
	</bean>
	
</beans>

And my Controller class:

package view;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import bus.LocalBUS;

public class LocalVIEW extends MultiActionController {

	/** Logger for this class and subclasses */
	protected final Log logger = LogFactory.getLog(getClass());

	private static Log log = LogFactory.getLog(LocalVIEW.class);

	protected LocalBUS localBUS;

	public LocalBUS getLocalBUS() {
		return localBUS;
	}

	public void setLocalBUS(LocalBUS localBUS) {
		this.localBUS = localBUS;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public ModelAndView hnd_firstPage(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		try {
			ConcurrentMap map = new ConcurrentHashMap();
			map.put("ad", "TK");
			logger.info("SpringappController - returning firstPage view...   TKTK");
			return new ModelAndView("firstPage", map);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}

firstPage.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My First MVC Page</title>
</head>
<body>
<p>This is my name : ${ad}</p>
</body>
</html>