Java 我在同时运行两个控制器时遇到控制器映射问题

Java 我在同时运行两个控制器时遇到控制器映射问题,java,xml,spring-mvc,Java,Xml,Spring Mvc,我有两个控制器,一个用于通过数据库登录,另一个用于在spring java中在数据库中插入值。我在映射它们时出错。如何在执行过程中映射这两个控制器。错误表明它有一些引用问题。当我只运行登录控制器时,它工作正常,但一旦我将注册控制器添加到其中,它就会失败。实际上登录后需要注册控制器 enter code here package com.login.controller; import javax.servlet.http.HttpServletRequest; import javax.ser

我有两个控制器,一个用于通过数据库登录,另一个用于在spring java中在数据库中插入值。我在映射它们时出错。如何在执行过程中映射这两个控制器。错误表明它有一些引用问题。当我只运行登录控制器时,它工作正常,但一旦我将注册控制器添加到其中,它就会失败。实际上登录后需要注册控制器

enter code here
package com.login.controller;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
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 com.login.bean.BorewellBean;
import com.login.delegate.BorewellDelegate;
@Controller
@RequestMapping(value ="/fillup")
@Component
public class BorewellController {

@Autowired
private BorewellDelegate borewelldelegate;

@RequestMapping(method=RequestMethod.GET)
public ModelAndView fillup(HttpServletRequest request,HttpServletResponse     response)
{
    ModelAndView model=new ModelAndView("loginsuccess");
    BorewellBean bean=new BorewellBean();
    model.addObject("bean",bean);
    return model;
}

@RequestMapping(method=RequestMethod.POST )
public ModelAndView executefillup(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("bean")BorewellBean bean)
{   

    ModelAndView model=null;
    try{
        boolean isValidUser=borewelldelegate.setvalue(bean.getBid(),bean.getDate(),bean.getStart(),bean.getStop());
                if(isValidUser)
                {
                    System.out.println("entry done");
                    request.setAttribute("bid",bean.getBid());
                    model=new ModelAndView("welcome");
                }
                else
                {
                    model=new ModelAndView("loginsuccess"); 
                }       
    }
    catch(Exception e)
    {
    }
    return model;


}
}
LoginController.java

enter code here
package com.login.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
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 com.login.bean.BorewellBean;
import com.login.bean.LoginBean;
import com.login.delegate.BorewellDelegate;
import com.login.delegate.LoginDelegate;

@Controller
@RequestMapping("/loginform")
public class LoginController {

@Autowired
private LoginDelegate loginDelegate;


@RequestMapping(method=RequestMethod.GET)
public ModelAndView showLogin(HttpServletRequest request,HttpServletResponse response)
{
    ModelAndView model=new ModelAndView("login");
    LoginBean loginbean= new LoginBean();
    model.addObject("loginBean",loginbean);
    return model;
}

@RequestMapping(method=RequestMethod.POST)
public ModelAndView executeLogin(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("loginBean")LoginBean loginBean)
{   
    ModelAndView model=null;
    try{
        boolean isValidUser=loginDelegate.isValidUser(loginBean.getUsername(),loginBean.getPassword());
                if(isValidUser)
                {
                    System.out.println("Login successful");
                    request.setAttribute("loginUser",loginBean.getUsername());


                    model=new ModelAndView("loginsuccess");
                }
                else
                {
                    model=new ModelAndView("login");    
                }       
    }
    catch(Exception e)
    {
    }
    return model;

}
 }



SpringBeanConfiguration.xml
<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">

  <bean id="loginDelegate" class="com.login.delegate.LoginDelegate">
    <property name="loginservice" ref="userService"></property>
 </bean>

<bean id="userService" class="com.login.service.UserServiceImpl">
    <property name="userDao" ref="userDao"></property>
</bean>

<bean name="userDao" class="com.login.dao.UserDaoImpl">
    <property name="dataSource" ref="dataSource"></property>
</bean>

 <bean id="borewelldelegate" class="com.login.delegate.BorewellDelegate">
    <property name="borewellservice" ref="borewellserviceimpl">     </property>
</bean>

<bean id="borewellserviceimpl" class="com.login.service.Borewellimpl" >
    <property name="borewelldao" ref="borewelldao"></property>
</bean>

<bean name="borewelldao" class="com.login.dao.Borewelldaoimpl" >
    <property name="dataSource" ref="dataSource"></property>
</bean>  

<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="rat" />
</bean>

</beans>
在此处输入代码
包com.login.controller;
导入javax.servlet.http.HttpServletRequest;
导入javax.servlet.http.HttpServletResponse;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Component;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.servlet.ModelAndView;
导入com.login.bean.borewelbean;
导入com.login.bean.LoginBean;
导入com.login.delegate.BorewellDelegate;
导入com.login.delegate.LoginDelegate;
@控制器
@请求映射(“/loginform”)
公共类登录控制器{
@自动连线
私人登录者登录者登录者;
@RequestMapping(method=RequestMethod.GET)
公共模型和视图显示登录(HttpServletRequest请求、HttpServletResponse响应)
{
ModelAndView模型=新的ModelAndView(“登录”);
LoginBean LoginBean=新LoginBean();
addObject(“loginBean”,loginBean);
收益模型;
}
@RequestMapping(method=RequestMethod.POST)
公共模型和视图执行器登录(HttpServletRequest请求,HttpServletResponse响应,@ModelAttribute(“loginBean”)loginBean loginBean)
{   
ModelAndView model=null;
试一试{
布尔值isValidUser=loginDelegate.isValidUser(loginBean.getUsername(),loginBean.getPassword());
if(isValidUser)
{
System.out.println(“登录成功”);
request.setAttribute(“loginUser”,loginBean.getUsername());
模型=新模型和视图(“登录成功”);
}
其他的
{
模型=新模型和视图(“登录”);
}       
}
捕获(例外e)
{
}
收益模型;
}
}
SpringBeanConfiguration.xml
Servlet dispatcher的我的错误HTTP Status 500-Servlet.init()引发异常 创建名为“borewellserviceimpl”的bean时出错:自动连线依赖项的注入失败;嵌套异常为org.springframework.beans.factory.BeanCreationException:无法自动连接字段:private com.login.dao.Borewelldao com.login.service.Borewellimpl.Borewelldao;嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到依赖项类型为[com.login.dao.Borewelldao]的匹配bean:至少需要1个符合此依赖项autowire候选项条件的bean。依赖项注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)} Login.jsp 在这里输入代码


在此处插入标题
用户名:
密码:

在您的服务实现类中使用@Service,并且在Dao层中,必须在所有Dao类中使用@Repository

也许您尝试映射相同的url路径?很难说没有看到你的代码或显示错误添加你的控制器class@michalsol我的代码就在上面。你使用MVC模式吗?我在上面的所有类中都使用过它。但是错误是一样的。我应该也使用@Autowired注释吗?不需要在类上面使用Autowired注释。另外,若您使用annotations服务,Reposiory意味着不需要在SpringBeanConfiguration.xml中创建bean,所以请删除它。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form:form  action="loginform.html"  modelAttribute="loginBean" > 
<table>
<tr>
<td>User Name:<FONT color="red"><form:errors path="username" /></FONT>      </td>
</tr>
<tr>
<td><form:input path="username" /></td>
</tr>
<tr>
<td>Password:<FONT color="red"><form:errors path="password" /></FONT>   </td>
</tr>
<tr>
<td><form:password path="password" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
</form:form>
</body>
</html>