2016-10-25 16 views
2

私はこのエラーが発生しており、なぜ私は理解できません。私はその道を信じています。それを何回か変更しようとしましたが、成功しませんでした。春の間違ったパス

*************************** 
APPLICATION FAILED TO START 
*************************** 

Description: 

Field loginDelegate in com.codeEvaluator.controller.LoginController required a bean of type 'com.codeEvaluator.delegate.LoginDelegate' that could not be found. 


Action: 

Consider defining a bean of type 'com.codeEvaluator.delegate.LoginDelegate' in your configuration. 


Process finished with exit code 1 

これは私のsprinBeanConfiguration.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.codeEvaluator.delegate.LoginDelegate"> 
    <property name="userService" ref="userService"></property> 
</bean> 

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

<bean name="userDao" class="com.codeEvaluator.dao.impl.UserDaoImpl"> 
    <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/codeevaluator" /> 
    <property name="username" value="root" /> 
    <property name="password" value="" /> 
</bean> 

マイspringWeb.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"> 

<context:component-scan base-package="com.jcg" /> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/jsp/" /> 
    <property name="suffix" value=".jsp" /> 

<import resource="springBeanConfiguration.xml"/> 
です

コントローラクラス

package com.codeEvaluator.controller; 

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

import org.springframework.beans.factory.annotation.Autowired; 
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.codeEvaluator.delegate.LoginDelegate; 
import com.codeEvaluator.viewBean.LoginBean; 


@Controller 
public class LoginController 
{ 
     @Autowired 
    private LoginDelegate loginDelegate; 

    @RequestMapping(value="/login",method=RequestMethod.GET) 
    public ModelAndView displayLogin(HttpServletRequest request, HttpServletResponse response, LoginBean loginBean) 
    { 
     ModelAndView model = new ModelAndView("login"); 
     //LoginBean loginBean = new LoginBean(); 
     model.addObject("loginBean", loginBean); 
     return model; 
    } 
    @RequestMapping(value="/login",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("User Login Successful"); 
          request.setAttribute("loggedInUser", loginBean.getUsername()); 
          model = new ModelAndView("welcome"); 
        } 
        else 
        { 
          model = new ModelAndView("login"); 
          request.setAttribute("message", "Invalid credentials!!"); 
        } 

      } 
      catch(Exception e) 
      { 
        e.printStackTrace(); 
      } 

      return model; 
    } 
} 

これは、プロジェクトの図です。

enter image description here

login.jspをデJSPパッケージ内です。

+0

web.xmlを共有して、アプリケーションコンテキストの設定を確認できます。 –

答えて

2

変更

<context:component-scan base-package="com.jcg, com.codeEvaluator" /> 

へとインポートは、これらのアノテーションを追加するには、 "sprinBeanConfiguration.xml" ファイルでこの

<import resource="classpath:springBeanConfiguration.xml"/> 

または

<import resource="classpath*:springBeanConfiguration.xml"/> 
+0

同じエラーです。 :( –

0

のようなものでなければなりません<context:component-scan base-package="com.codeEvaluator" /><context:annotation-config>注釈を可能にする "@Autowired"

関連する問題