This question already has answers here:
Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request with URI [...] in DispatcherServlet"?
(13 answers)
Closed 6 years ago.
I´m getting a mapping error on my application, any help would be greatly appreciated! =)
Error message: No mapping found for HTTP request with URI [/springapp/priceincrease.htm] in DispatcherServlet with name 'springapp'
You can find some code below:
PriceIncreaseFormController.java
#Controller
#RequestMapping(value="/priceincrease.htm")
public class PriceIncreaseFormController {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog(getClass());
#Autowired
private ProductManager productManager;
#RequestMapping(method = RequestMethod.POST)
public String onSubmit(#Valid PriceIncrease priceIncrease, BindingResult result)
{
if (result.hasErrors()) {
return "priceincrease";
}
int increase = priceIncrease.getPercentage();
logger.info("Increasing prices by " + increase + "%.");
productManager.increasePrice(increase);
return "redirect:/hello.htm";
}
#RequestMapping(method = RequestMethod.GET)
protected PriceIncrease formBackingObject(HttpServletRequest request) throws ServletException {
PriceIncrease priceIncrease = new PriceIncrease();
priceIncrease.setPercentage(15);
return priceIncrease;
}
public void setProductManager(ProductManager productManager) {
this.productManager = productManager;
}
public ProductManager getProductManager() {
return productManager;
}
}
app-config.xml
<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: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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean id="productManager" class="com.companyname.springapp.service.SimpleProductManager">
<property name="products">
<list>
<ref bean="product1"/>
<ref bean="product2"/>
<ref bean="product3"/>
</list>
</property>
</bean>
<bean id="product1" class="com.companyname.springapp.domain.Product">
<property name="description" value="Lamp"/>
<property name="price" value="5.75"/>
</bean>
<bean id="product2" class="com.companyname.springapp.domain.Product">
<property name="description" value="Table"/>
<property name="price" value="75.25"/>
</bean>
<bean id="product3" class="com.companyname.springapp.domain.Product">
<property name="description" value="Chair"/>
<property name="price" value="22.79"/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
<!-- Scans the classpath of this application for #Components to deploy as beans -->
<context:component-scan base-package="com.companyname.springapp.web" />
<!-- Configures the #Controller programming model -->
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<display-name>Springapp</display-name>
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
You forgot to add handler mapping in your application context:
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
There problem in your GET method : formBackingObject.
Depends upon your requirement it should return to view or make it REST method.
Case 1 : return to view (JSP,HTML,XSLT...)
#RequestMapping(value="/priceincrease.htm",method = RequestMethod.GET)
protected String formBackingObject(HttpServletRequest request,Model model) throws ServletException {
PriceIncrease priceIncrease = new PriceIncrease();
priceIncrease.setPercentage(15);
model.addAttribute("priceIncrease",priceIncrease);
return "view_name";
}
Case 2 : REST method using #ResponseBody (jackson.core Jar is necessary)
#RequestMapping(value="/priceincrease.htm",method = RequestMethod.GET)
#ResponseBody
protected PriceIncrease formBackingObject(HttpServletRequest request) throws ServletException {
PriceIncrease priceIncrease = new PriceIncrease();
priceIncrease.setPercentage(15);
return priceIncrease;
}
Here you have modify controller's parent mapping (simply remove it) for both cases
#Controller
public class PriceIncreaseFormController {
}
Related
Stuck with an exception and below is the log:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'speaker': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public final void org.mybatis.spring.support.SqlSessionDaoSupport.setSqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate); nested exception is java.lang.NoSuchMethodError: org.springframework.core.MethodParameter.getNestedParameterType()Ljava/lang/Class
java web service:
#WebService
public class voiceRecognition extends SpringBeanAutowiringSupport {
#Autowired
private Speaker speaker;
#WebMethod
public void test() {
String userid = "111";
String enrollmentid = "111";
try{
String test1 = speaker.getEnrollmentId(userid);
System.out.println(test1);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Speaker.java:
package ph.com.aub.mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
#Service
public interface Speaker {
public String getEnrollmentId(#Param("userid") String userid);
}
Speaker.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace = "ph.com.aub.mapper.Speaker">
<select id = "getEnrollmentId" resultType = "string" parameterType = "string">
Select enrollmentid from speakerids where userid = #{userid}
</select>
</mapper>
web.xml:
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app 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"
version="2.5">
<servlet>
<servlet-name>voiceRecognitionPort</servlet-name>
<!--<servlet-class>ph.com.aub.domain.voiceRecognition</servlet-class>-->
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>voiceRecognitionPort</servlet-name>
<url-pattern>/voiceRecognitionPort</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-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="ph.com.aub.domain.voiceRecognition"/>
<context:component-scan base-package="ph.com.aub.mapper"/>
<context:annotation-config/>
<bean id="dataSourceSpeaker" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="Speakerdata"/>
</bean>
<bean id="sqlSessionFactorySpeaker" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceSpeaker"/>
<property name="typeAliasesPackage" value="ph.com.aub.domain"/>
<property name="configLocation" value="/WEB-INF/mybatis-config.xml"/>
</bean>
<bean id="mapperSpeaker" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorySpeaker" />
</bean>
</beans>
I believe you configure the basePackage in MapperScannerConfigurer incorrectly. It should be package that containing the mapper class rather than the mapper class itself. So try to change the basePackage to:
<bean id="mapperSpeaker" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="ph.com.aub.mapper" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorySpeaker" />
</bean>
I am creating a spring web application with help of hibernate. I have created spring-dipatcher-servlet.xml for all the configuration. I want to access the database using hibernate without creating the hibernate.cfg.xml file as I am using spring. I am getting Null Pointer Exception while accessing the Session Factory in DAO.
Following are the snippets of what I have done till now.
----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" 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>quiz_mcq</display-name>
<welcome-file-list>
<welcome-file>welcome.htm</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
---spring-dispatcher-servlet---
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.quiz_mcq.controller" />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/quiz_mcq" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.quiz_mcq.bean"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
---controller ---
#Controller
public class QuizMcqController {
UserService userService;
#RequestMapping(value="/welcome.htm")
public ModelAndView redirectToLoginPage(){
ModelAndView modelAndView = new ModelAndView("login");
return modelAndView;
}
#RequestMapping(value="/AuthenticateUser.htm", method = RequestMethod.POST)
public ModelAndView authenticateUser(#RequestParam("username") String username, #RequestParam("password")String password){
userService = new UserService();
boolean flag = userService.authenticate(username,password);
if(flag){
ModelAndView modelAndView = new ModelAndView("login");
return modelAndView;
}
else{
ModelAndView modelAndView = new ModelAndView("wrong");
return modelAndView;
}
}
}
--- Service ---
public class UserService {
User user;
UserDao dao;
public boolean authenticate(String username, String password) {
user = new User();
user.setUsername(username);
user.setPassword(password.toCharArray());
if(dao.authenticateUser(user))
{
return true;
}
return false;
}
}
---DAO ---
#Repository
public class UserDao implements IUser {
#Autowired
SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
#Override
public boolean authenticateUser(User user) {
String username = user.getUsername();
char[] password = user.getPassword();
System.out.println(username +" <----> "+password);
String hql = "from User where username='username' and password ='password'";
Query query = getSessionFactory().openSession().createQuery(hql);
List list = new ArrayList();
list = query.list();
if (list.size() > 0 && list != null) {
return true;
}
return false;
}
}
How can I resolve my issue, what I am doing wrong?
Thanks in advance. Your help is appreciated.
here the problem is currently your dispatcher servlet does not know how to create and set the bean SessionFactory from. (As you see, your setSessionFactory is in UserDao class )
you may need to declare UserDao bean in spring-dispatcher-servlet.xml.
for eg:
<bean id="userDAO" class="your.package.nameforUserDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
I am using pure xml in spring configuration. I have applicationContext.xml and servletContext.xml. In applicationContext.xml, I created the dao and service bean while in servletContext.xml, I created controller bean that references the service bean in applicationContext. Then in controller class, I have this code to initialize the bean
private PersonService personService
public void setPersonService(PersonService personService){
this.personService = personService;
}
When I call method in personService, Im getting a null pointer exception. I guess that the service bean is null. What am I doing wrong?
This is my beans xml
applicationContext.xml
<bean id="personDao" class="com.training.hibernate.dao.impl.PersonDaoImpl">
<constructor-arg>
<ref bean="sessionFactory"/>
</constructor-arg>
</bean>
<bean id="personService" class="com.training.hibernate.services.impl.PersonServiceImpl">
<constructor-arg>
<ref bean="personDao"/>
</constructor-arg>
</bean>
servletContext.xml
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
<bean class="com.training.hibernate.controller.PersonController">
<property name="personService" ref="personService"/>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
This is my controller
public class PersonController extends MultiActionController {
private PersonService personService;
public void setPersonService(PersonService PersonService){
this.personService = personService;
}
public ModelAndView getAllPersons(HttpServletRequest request, HttpServletResponse response) throws Exception{
List<PersonDto> personDtos = personService.getAllPersons();
ModelAndView model = new ModelAndView("index");
model.addObject("persons",personDtos);
model.addObject("roles",personService.getRoles());
return model;
}
public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception{
ModelAndView model = new ModelAndView("person");
return model;
}
}
web.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Spring Web Application</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servletContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
I have searched the net and found few solution,but still i am facing the same problem.
I am trying to create a web application with Angularjs as frontend end spring rest as back end.
I am able to access the url resource through $http.post methos, but while the binding of data to pojo doesnt happen. The values are always null.
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>login</display-name>
<servlet>
<servlet-name>springws</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springws</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
My dispatcher servlet configuration
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
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">
<context:component-scan base-package="com.junaid.spring.webservice" />
<!-- Configures the #Controller programming model -->
<mvc:annotation-driven />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- Drop and re-create the database schema on startup -->
<prop key="hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
</beans>
Angualrjs controller file
login.controller('RegisterController',['$scope','userFactory', function($scope, userFactory) {
$scope.user;
$scope.saveUser = function(){
userFactory.saveUser($scope.user);
};
}]);
Angularjs factory js file
angular.module('login')
.factory('userFactory' , ['$http', function($http){
var userFactory= {};
userFactory.authenticate = function(user){
console.log(user.name);
console.log(user.password);
};
userFactory.saveUser = function(user){
console.log(user.name);
console.log(user.password);
console.log(user.phone);
console.log(user.email);
$http.post('rest/register', user).success(console.log("registered"));
};
userFactory.forgotPassword = function(user){
console.log(user.name);
};
return userFactory;
}]);
Jsp page invokes userFactory.saveUser() function which in turns call my rest service,
my controller class
#Controller
public class UserController {
#RequestMapping(value = "/authenticate", method = RequestMethod.GET)
public #ResponseBody String getState(UserData ud) {
System.out.println(ud.getPassword());
return "true";
}
#RequestMapping(value = "/register", method = RequestMethod.POST)
public #ResponseBody String registerUser(Users ud) {
System.out.println(ud.getPassword());
return "true";
}
}
The println statements always prints null.
Can anyone tell me where i am going wrong.
You need the #RequestBody in your getState and registerUser methods before the Argument. Furthermore getState must be a POST Method.
#Controller
public class UserController {
#RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public #ResponseBody String getState(#RequestBody UserData ud) {
System.out.println(ud.getPassword());
return "true";
}
#RequestMapping(value = "/register", method = RequestMethod.POST)
public #ResponseBody String registerUser(#RequestBody Users ud) {
System.out.println(ud.getPassword());
return "true";
}
}
I have a simple standalone application with spring (Main class + bean class). It creates MBean (JMX).
It just start up my bean.
main class:
public class Main {
public static void main(final String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("cont.xml");
try {
Thread.sleep(1000 * 60 * 5);
} catch (final Throwable t) {}
}
}
Bean
public class Test {
private String val = "";
public String getVal() {
return val;
}
public void setVal(String v) {
val = v;
}
cont.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.xsd"
default-lazy-init="true">
<bean id="test" class="test.Test" />
<bean class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler" >
<property name="managedMethods">
<list>
<value>getVal</value>
<value>setVal</value>
</list>
</property>
</bean>
</property>
<property name="beans">
<map>
<entry key="bean:name=Test" value-ref="test"/>
</map>
</property>
</bean>
</beans>
How can I run the same example on tomcat?
Thanks!
Use
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cont.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
in your web.xml. This will instantiate all beans configured in cont.xml.