How to enable #RequiresPermissions in Spring MVC project? - spring-mvc

Having spent days trying to get my head around AOP, I have no option than to lay out my code and hope the good guys on the internet will help me.
My dispatcher-servlet.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version=".0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.company.project"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/WEB-INF/resources/, file:${catalina.home}/project/resources/" />
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<!--
The index controller.
-->
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
</beans>
applicationContext.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="com.company.project"/>
<!-- Transaction Management -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
<value>/WEB-INF/c3p0.properties</value>
<value>/WEB-INF/application.properties</value>
</list>
</property>
</bean>
<!-- With c3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.company.project.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop>-->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
<prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop>
<prop key="hibernate.connection.url">${jdbc.url}</prop>
<prop key="hibernate.connection.username">${jdbc.username}</prop>
<prop key="hibernate.connection.password">${jdbc.password}</prop>
<!-- <prop key="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</prop>-->
<prop key="hibernate.c3p0.acquire_increment">1</prop>
<prop key="hibernate.c3p0.idle_test_period">300</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.max_statements">100</prop>
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1;</prop>
<prop key="hibernate.c3p0.testConnectionOnCheckin">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="shiroFilter" class= "org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/verify.jsp"/>
<property name="successUrl" value="/index"/>
<property name="filterChainDefinitions">
<value>
/verify.jsp = authc
/secure/** = authc
/logout.htm = logout
/api/test/** = anon
/api/** = jwtv
</value>
</property>
</bean>
<bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
<property name="redirectUrl" value="/login.jsp"/>
</bean>
<bean id="annon" class="org.apache.shiro.web.filter.authc.AnonymousFilter">
</bean>
<bean id="jwtg" class="com.company.project.model.api.ApiGuard">
</bean>
<bean id="jwtv" class="com.company.project.model.api.JWTVerifyingFilter">
</bean>
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- Single realm app. If you have multiple realms, use the 'realms' property instead. -->
<property name="realm" ref="jdbcRealm"/>
<property name="cacheManager" ref="cacheManager"/>
<!-- By default the servlet container sessions will be used. Uncomment this line
to use shiro's native sessions (see the JavaDoc for more): -->
<!-- <property name="sessionMode" value="native"/> -->
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<!-- Enable Shiro Annotations for Spring-configured beans. Only run after
the lifecycleBeanProcessor has run: -->
<bean id="annotationProxy"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
<bean id="jdbcRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
<property name="credentialsMatcher" ref = "sha256Matcher"/>
<property name="authenticationQuery" value = "SELECT password, salt FROM admin WHERE email = ?"/>
<property name="permissionsLookupEnabled" value = "true"/>
<property name="userRolesQuery" value = "SELECT role_name FROM admin_role WHERE email = ?"/>
<property name="permissionsQuery" value = "SELECT permission FROM roles_permission WHERE role_name = ?"/>
<property name="saltStyle" value = "COLUMN"/>
<property name="dataSource" ref = "dataSource"/>
</bean>
<bean id="sha256Matcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher" >
<property name="hashAlgorithmName" value = "SHA-256"/>
</bean>
<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000"/>
</bean>
</beans>
If I comment out the part:
<bean id="annotationProxy"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor" />
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
the project runs but the #RequiresPermissions annotation is useless. When I run the project with these config Error is:
[http-nio-8084-exec-100] WARN
org.springframework.web.context.support.XmlWebApplicationContext -
Exception encountered during context initialization - cancelling
refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'myController': Unsatisfied
dependency expressed through field 'myService'; nested exception
is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'myService' is expected to be of type
[com.company.project.service.myService] but was actually of type
[com.sun.proxy.$Proxy530] [http-nio-8084-exec-100] ERROR
org.springframework.web.context.ContextLoader - Context initialization
failed
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'myController': Unsatisfied
dependency expressed through field 'myService'; nested exception
is org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named 'myService' is expected to be of type
[com.company.project.service.myService] but was actually of type
[com.sun.proxy.$Proxy530] at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569)
My controller classes are smth like:
#RestController
#RequestMapping(value = "/api/my")
public class MyApis {
#Autowired
MyService myService;
#RequestMapping(method = RequestMethod.GET, value = "/profile/save")
#RequiresPermissions("profile:save")
public void saveProfile(#RequestParam(value = "first-name") String firstName, #RequestParam(value = "last-name") String lastName,HttpServletRequest request) {
Profile profile = new Profile();
profile.setFirstName(firstName);
profile.setLastName(lastName);
myService.insert(profile);
}
}
Please help me figure out setting up Shiro annotations. Thank you.

Shiro has a Spring Boot example that uses Shiro's annotations on a controller. And a non-boot example too

Related

LocalContainerEntityManagerFactoryBean hibernate configuration bean is initialized in a loop

I have my hibernate entity manager factory declared in jpa.xml, hazecast configured in hazelcast.xml and I have domain model setup and I have corresponding componentContext.xml present in the domain model project where my entity manager factory class is implemented in it. But the problem I am
facing is that my bean in componentContext.xml is getting intialized in a loop (observed from hibernate.log)
My Web.xml has only com.sun.faces.config.ConfigureListener listenere configured.
My Stack
Spring - 4.3.8
Hibernate - 5.0.10-FINAL
hazelcast-hibernate5 - 1.3.0
JPA.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:context="http://www.springframework.org/schema/context"
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">
<context:property-placeholder location="classpath:dataSources.properties" />
<!-- Default JPA configuration for OpenJPA and Hibernate -->
<!-- Hibernate configuration -->
<bean id="hibernateEntityManagerFactory" abstract="true" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.max_fetch_depth" value="3" />
<entry key="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<entry key="hibernate.enable_lazy_load_no_trans" value="true" />
<entry key="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<entry key="hibernate.current_session_context_class" value="jta" />
</map>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${dbDialect}" />
</bean>
</property>
</bean>
<alias name="hibernateEntityManagerFactory" alias="entityManagerFactory" />
</beans>
componentContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
xmlns:jpa="http://www.springframework.org/schema/data/jpa">
<context:component-scan base-package="com.volvo.myfirstdomain.base />
<context:annotation-config />
<!-- JPA EntityManagerFactory -->
<!-- Based on choice of implementation between OpenJPA and Hibernate, parent attribute in bean should be set. For OpenJPA: parent = "openJpaEntityManagerFactory"
For Hibernate: parent = "hibernateEntityManagerFactory" Here, OpenJPA is chosen as you can see below. -->
<bean id="myDomainEntityManagerFactory" parent="entityManagerFactory">
<property name="persistenceUnitName" value="MYDomainPU" />
<property name="packagesToScan" value="com.volvo.myfirstdomain.entity" />
<property name="jpaProperties">
<props>
<prop key="hibernate.default_schema">DOMAIN_ONE</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect </prop>
<prop key="hibernate.cache.region.factory_class">com.hazelcast.hibernate.HazelcastCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="javax.persistence.sharedCache.mode">ENABLE_SELECTIVE</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="dataSource" />
</bean>
</beans>
I have tried debugging multiple times but I am not able to figure out why the initialzing is happening multiple times (as if in a loop). Any pointers greatly appreciated!
I finally figured out the reason! There was an additional #ComponentScan annotation specified in the application configuration class which was causing the loop to be triggered.

Hibernate validator could not get value by key

My project use spring mvc and hibernate validator .And I am trying to make it support multi-language.
This is my spring-i18N file
<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieMaxAge" value="604800"/>
<property name="defaultLocale" value="zh_CN" />
<property name="cookieName" value="language"></property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:i18N/messages</value>
<value>classpath:i18N/validation</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
<property name="useCodeAsDefaultMessage" value="false"/>
</bean>
<mvc:annotation-driven validator="validator" />
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
<property name="validationMessageSource" ref="messageSource"/>
</bean>
</beans>
And my problem is,while I use annotations in bean file,like this,
#Size(min=6, max=25,message="{password_length_require}")
private String password;
and in the validation_en_US.properties,I do this
password_length_require=The password length require more than 5 and less 25
The result is that page will output "{password_length_require} ".
On the other hand,in my controller,I use
bindingResult.rejectValue("password", "password_length_require");
It will work fine...
Can anybody help me?
I had the same problem before,it took me long time to solve it.
Just like me,there might be something wrong with the following configuration.
<property name="basenames">
<list>
<value>classpath:i18N/messages</value>
<value>classpath:i18N/validation</value>
</list>
</property>
The value of property "basenames" must be full path where your validation messages files save in your project.For example,if validation message files are in package named "org.example.config.i18N.messages", you should config the xml like this:
<value>classpath:org/example/config/i18N/messages</value>
So maybe you need to check whether or not your configuration is right.
The above is my experience, hope to help you.

integrating tiles in spring3, getting java.lang.NoSuchFieldError: PATCH exception

Let me know how to initialize tiles from dispatcher and application context and if any changes required in web.xml,
this is my tiles.xml
<definition name="contact" extends="mainLayout">
<put-attribute name="title" value="Contact Manager" />
<put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />
</definition>
</tiles-definitions>
in application context i have used
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="requestContextAttribute" value="requestContext"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
and dispatcher looks like this
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
indexController</prop>-->
newController
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
<property name="definitions">
<list>
<value>WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="viewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
In Dispatcher-Servlet
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
In web.xml use this code
<listener>
<listener-class>org.apache.tiles.web.startup.simple.SimpleTilesListener</listener-class>
</listener>
rest is not required for spring-tiles application, tiles.xml is depended on your requirement

Not able to wire entityManager with applicationContext bean

I am facing a problem to wire entity manager with the bean present in application context.
whenever i do some operation it gives NullPointerException.
this is my applicationContext.xml file
<?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: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">
<context:component-scan base-package="com.ajit.retail"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://localhost/retail"/>
<property name="username" value="retail_user"/>
<property name="password" value="password"/>
</bean>
<bean id="entityManagerOne" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="databasePlatform" value="org.hibernate.dialect.PostgreSQL82Dialect"/>
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerOne"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
this is the java file in which i am creating the entity manager
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
public class AbstractRepository {
#PersistenceContext
EntityManager entityManager;
}
so whenever i use this entity manager it gives null pointer exception
please help!
Your entity manager bean is called enetityManagerOne, but the variable is called entityManager. Maybe renamme your bean in your XML file:
<bean id="entityManager" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
Another solution could be you forgot the following bean declarations:
For the support for transaction:
<tx:annotation-driven/>
The support for parsing JPA annotations:
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
my application context was not on the correct place (src/main/resources). Now I put that there and its working.
Use this code in your dispatcher-servlet.xml
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations">
<list>
<value>classpath*:META-INF/persistence.xml</value>
</list>
</property>
<property name="defaultDataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager" ref="persistenceUnitManager"/>
<property name="persistenceUnitName" value="etray"/>
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="java:/prateek" />
<!-- we plan to use JTA transactions and declare them using annotations -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- to inject instances of EntityManager using #PersistenceContext annotation -->
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
it resolve my problem, hope it will help.

Configuring multiple controllers in dispatcher servlet

I am new to spring-hibernate integration.
I am trying to enter data into database through jsp form, and I am getting a null pointer exception when the object is trying to persit.
I checked if the object is receiving values, and it does.
The reason I feel is because the dispatcher servelet is not allowing me to pass the value through.
Bellow is my dispatcher-servlet.
If any one can me show me the way to configure multiple controllers in dispatcher servelet it would be great.
<?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:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- maps request URLs to Controller names -->
<!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/> -->
<!-- bean class="com.skopic.web.controller.UserController" /-->
<bean name="/index/*.htm" class="com.skopic.web.controller.IndexController" >
<!-- <property name="UserDAO" ref="myUserDAO" /> -->
</bean>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:skopicportal.${SKAPP_ENV}.properties</value>
</list>
</property>
</bean>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<!-- <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.skopic.web.controller.Tenant</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="myTenantDAO" class="com.skopic.web.controller.TenantDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean> -->
<!-- User bean -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.skopic.web.controller.User</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="myUserDAO" class="com.skopic.web.controller.UserDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<bean name="/user/*.htm" class="com.skopic.web.controller.UserController" >
<property name="UserDAO" ref="myUserDAO" />
</bean>
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/> -->
<mvc:annotation-driven/>
<context:component-scan base-package="com.skopic.service"/>
<context:component-scan base-package="com.skopic.web.controller"/>
</beans>

Resources