java.lang.IllegalStateException:Autowired annotation需要至少一个参数

前端之家收集整理的这篇文章主要介绍了java.lang.IllegalStateException:Autowired annotation需要至少一个参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

无法自动装配和运行Spring Web应用程序.

错误

java.lang.IllegalStateException: Autowired annotation requires at least one argument: public main.java.com.springapp.mvc.controller.DSLRServletController()

DSLRServletController:

package main.java.com.springapp.mvc.controller;

import main.java.com.springapp.mvc.dao.DSLRDAO;
import main.java.com.springapp.mvc.model.DSLR;
import main.java.com.springapp.mvc.pckg.DSLRForm;
import main.java.com.springapp.mvc.pckg.DSLRValidaor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.bind.annotation.RequestParam;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;

@Controller
public class DSLRServletController   {
    static Logger logger = Logger.getLogger(DSLRServletController.class);


    private DSLR DSLR;
    private DSLRDAO dslrDAO;
    private DSLR dslr;



    @Autowired
    public DSLRServletController() {
        this.dslrDAO = new DSLRDAO();
    }

    public void init() {logger.error("DSLRServlet.init(): just started"); }

@RequestMapping(value = "/s",method = RequestMethod.GET)
public String showHTMLResponse(@modelattribute("dslrs") DSLR dslrs[],@modelattribute("dslr") DSLR dslr,@modelattribute("dslrErrors") HashMap dslrErrors,@modelattribute ("dslrform") DSLRForm dslrForm,@RequestParam("id") String paramId,@RequestParam("action") String paramAction,Model model){

    if(paramId == null || paramId.equals("")){
        //show_all_dslrs
        dslrs = getAllDslrs();    // DSLR adslrs[] -> to MODEL; HOW?
       return "dslrs";
    }else{
        //show_this_dslr;
        HashMap@modelattribute("dslrs") DSLR dslrs[],@modelattribute("dslrErrors") HashMap

为什么@Autowired注释会返回错误?怎么解决

最佳答案
构造函数不是有效的setter方法或实例变量

@Autowired
private DSLRDAO dslrDAO;
原文链接:https://www.f2er.com/spring/431816.html

猜你在找的Spring相关文章