我有这个错误。在localhost上一切都很好。错误发生在AWS上。可能是什么原因?
HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalStateException: Autowired annotation requires at least one argument: public com.bartek.controllers.AppController()
type Exception report
message Request processing failed; nested exception is java.lang.IllegalStateException: Autowired annotation requires at least one argument: public com.bartek.controllers.AppController()
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Autowired annotation requires at least one argument: public com.bartek.controllers.AppController()
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.IllegalStateException: Autowired annotation requires at least one argument: public com.bartek.controllers.AppController()
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:296)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
org.springframework.web.method.HandlerMethod.createWithResolvedBean(HandlerMethod.java:255)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:323)
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:61)
org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:351)
org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1131)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:936)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.39 logs.
@Controller
public class AppController {
@Autowired
public AppController(){
}
SessionFactory sessionFactory = HibernateUtil.getSessionAnnotationFactory();
@RequestMapping(path="/index", method=RequestMethod.GET)
public String index(){
return "index";
}
@RequestMapping(path="/addproject/add", method=RequestMethod.POST)
public String addProject(@ModelAttribute("person") Person person, Project project, Model model){
Session session = sessionFactory.getCurrentSession();
Person p = new Person();
p.setName(person.getName());
p.setSurname(person.getSurname());
p.setIndex(person.getIndex());
Project pr = new Project();
pr.setContent(project.getContent());
try {
session.beginTransaction();
List<Person> listPersons = new ArrayList<Person>();
listPersons.add(p);
pr.setPersons(listPersons);
session.save(pr);
session.save(p);
session.getTransaction().commit();
}
catch (RuntimeException e) {
session.getTransaction().rollback();
throw e;
}
return "redirect:/listprojects";
}
@RequestMapping(path="/addproject", method=RequestMethod.GET)
public String start(){
return "addproject";
}
@RequestMapping(path="/listprojects", method=RequestMethod.GET)
public String getListProjects(Model model){
Session session = sessionFactory.getCurrentSession();
try {
session.beginTransaction();
List<Project> listProjects = new ArrayList<Project>();
listProjects = session.createCriteria(Project.class).list();
model.addAttribute("lists", listProjects);
}
catch (RuntimeException e) {
session.getTransaction().rollback();
throw e;
}
return "listprojects";
}
@RequestMapping(path="/addperson", method=RequestMethod.GET)
public String addPersonSite(Model model){
Session session = sessionFactory.getCurrentSession();
try {
session.beginTransaction();
List<Project> titleProjects = new ArrayList<Project>();
titleProjects = session.createCriteria(Project.class).list();
model.addAttribute("titleList", titleProjects);
}
catch (RuntimeException e) {
session.getTransaction().rollback();
throw e;
}
return "addperson";
}
@RequestMapping(path="/addperson/add", method={RequestMethod.POST,RequestMethod.GET})
public String addPersonForm(@RequestParam(value = "nameProject", required=false) String nameProject, @ModelAttribute("person") Person person, Project project, Model model){
int idProject;
List<Person> listPersons = new ArrayList<Person>();
Session session = sessionFactory.getCurrentSession();
Person p = new Person();
p.setName(person.getName());
p.setSurname(person.getSurname());
p.setIndex(person.getIndex());
try {
session.beginTransaction();
List<Project> listProjects = new ArrayList<Project>();
listProjects = session.createCriteria(Project.class).list();
Project pr = new Project();
for(Project pro : listProjects){
if(pro.getContent().equals(nameProject)){
idProject = (pro.getId() - 1);
pr = listProjects.get(idProject);
listPersons = listProjects.get(idProject).getPersons();
listPersons.add(p);
pr.setPersons(listPersons);
}
}
session.saveOrUpdate(pr);
session.save(p);
session.getTransaction().commit();
}
catch (RuntimeException e) {
session.getTransaction().rollback();
throw e;
}
return "redirect:/listprojects";
}
}
............................................... .................................................. .................................................. ..................
答案 0 :(得分:3)
您已在默认构造函数上设置@Autowired
,这没有任何意义。没有任何自动装配,因此错误信息。