I have built a web project using spring framework and according to that i have added jar to it. But when I'm going to execute that it gives following error. Please provide me solution for this error.
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController' defined in file [D:\WebsiteDemo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\loginexample\WEB-INF\classes\com\login\controller\LoginController.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.methodSecurityMetadataSourceAdvisor': Cannot resolve reference to bean 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0': 1 constructor arguments specified but no matching constructor found in bean 'org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource#0' (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
My dispatcher file is
<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:component-scan base-package="com.login.controller"/>
<mvc:annotation-driven />
<security:global-method-security secured-annotations="enabled"/>
<security:http auto-config="true">
<security:intercept-url pattern="/main*" access="ROLE_ADMIN,ROLE_REGULAR_USER" />
<security:form-login login-page="/login" default-target-url="/main"
authentication-failure-url="/loginError"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="alpha" password="pass1" authorities="ROLE_ADMIN" />
<security:user name="beta" password="pass2" authorities="ROLE_REGULAR_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
LoginController code
package com.login.controller;
import java.security.Principal;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class LoginController {
@RequestMapping(value="/main", method = RequestMethod.GET)
public String printWelcome(ModelMap model, Principal principal ) {
String name = principal.getName();
model.addAttribute("username", name);
return "main_page";
}
@RequestMapping(value="/login", method = RequestMethod.GET)
public String login(ModelMap model) {
return "login_page";
}
@RequestMapping(value="/loginError", method = RequestMethod.GET)
public String loginerror(ModelMap model) {
model.addAttribute("error", "true");
return "login_page";
}
@Secured({"ROLE_REGULAR_USER","ROLE_ADMIN"})
@RequestMapping(value="/common", method = RequestMethod.GET)
public String common(ModelMap model) {
return "common_page";
}
@RequestMapping(value="/logout", method = RequestMethod.GET)
public String logout(ModelMap model) {
return login(model);
}
}