i am getting errors when using @Requestmapping in LoginController.java.
Getting errors like
Multiple markers at this line
- The attribute value is undefined for the annotation type
RequestMapping
- RequestMethod cannot be resolved to a variable
- The attribute method is undefined for the annotation type
RequestMapping
- RequestMapping cannot be resolved to a type and some other errors also.
Please check bean.xml file also.
LoginController.java
package control;
import model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.ui.ModelMap;
@Controller
public class LoginControl{
private ApplicationContext context = null;
private UserJDBCTemplate userJDBCTemplate = null;
public LoginControl(){
context = new ClassPathXmlApplicationContext("Beans.xml");
userJDBCTemplate = (UserJDBCTemplate)context.getBean("userJDBCTemplate");
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView userLogin() {
return new ModelAndView("login", "command", new User());
}
@RequestMapping(value = "/loginCheck", method = RequestMethod.POST)
public String checkUser(@ModelAttribute("SpringWeb")User user, ModelMap model) {
model.addAttribute("username", user.getUsername());
if(userJDBCTemplate.checkLogin(user)){
return "loginsuccess";
}
return "loginerror";
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public ModelAndView userAdd() {
return new ModelAndView("add", "command", new User());
}
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String addUser(@ModelAttribute("SpringWeb")User user, ModelMap model) {
model.addAttribute("username", user.getUsername());
if(userJDBCTemplate.create(user)){
return "addsuccess";
}
return "adderror";
}
}
beans.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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="control"/>
<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/login"/>
<property name="username" value="root"/>
<property name="password" value="infoobjects"/>
</bean>
<!-- Definition for userJDBCTemplate bean -->
<bean id="userJDBCTemplate" class="control.UserJDBCTemplate">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
ApplicationContextAwareto get a bean fromcontainer.