项目ZIP:http://goo.gl/ddhLg5
无法执行Spring Web应用程序,导致HTTP状态500错误。它还写出没有为DSLR找到默认构造函数,但实际上有一个默认构造函数。也许它与应用程序上下文或我的bean声明的方式有关?我的申请无法启动的原因是什么?
DSLR:
package main.java.com.springapp.mvc.model;
public class DSLR {
public DSLR() {
}
public void init() {}
private int dslrId;
private String model;
private int price;
private String description;
public int getDslrId() {
return dslrId;
}
public void setDslrId(int dslrId) {
this.dslrId = dslrId;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public String toString() {
return "DSLR [dslr=" + dslrId + ", model=" + model
+ ", price=" + price+ ", description=" + description+"]";
}
}
的web.xml
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
DSLRServletController-servlet.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="main.java.com.springapp.mvc" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="s" class="main.java.com.springapp.mvc.controller.DSLRServletController">
<property name="dslrDAO" ref="dslrDAO" />
<property name="DSLR" ref="DSLR" />
</bean>
<bean id="dslrDAO" class="main.java.com.springapp.mvc.dao.DSLRDAO">
</bean>
<bean id="DSLR" class="main.java.com.springapp.mvc.model.DSLR">
</bean>
</beans>
MVC-调度-servlet.xml中
<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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="main.java.com.springapp.mvc"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
错误:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [[Lmain.java.com.springapp.mvc.model.DSLR;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
type Exception report
message Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [[Lmain.java.com.springapp.mvc.model.DSLR;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
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 org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [[Lmain.java.com.springapp.mvc.model.DSLR;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:927)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [[Lmain.java.com.springapp.mvc.model.DSLR;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:108)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:770)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:363)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:439)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:427)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
java.lang.Class.getConstructor0(Class.java:2810)
java.lang.Class.getDeclaredConstructor(Class.java:2053)
org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveModelAttribute(HandlerMethodInvoker.java:770)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:363)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:439)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:427)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
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/7.0.52 logs.
主控制器类:
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 extends HttpServlet {
static Logger logger = Logger.getLogger(DSLRServletController.class);
private DSLR DSLR;
private DSLRDAO dslrDAO;
private DSLR dslr;
/* request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
List list = getActions(request, response);
response.setContentType("text/html; charset=UTF-8");*/
//@Autowired ???
public DSLRServletController() {
this.dslrDAO = new DSLRDAO();
}
public void init() {logger.error("DSLRServlet.init(): just started"); }
/*
/s GET
/s?id=1 GET
/s?action=save POST
/dslrservice?id=1&tm=<timestamp> GET
*/
@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;
return "dslrs";
}else{
//show_this_dslr;
HashMap<String,Object> dslrHashMap = getDSLRById(paramId);
dslr = (DSLR) dslrHashMap.get("dslr");
dslrForm = (DSLRForm)dslrHashMap.get("dslrForm");
dslrErrors = (HashMap)dslrHashMap.get("dslrErrors");
if(dslr != null){
// getServletConfig().getServletContext().getRequestDispatcher("/dslr.jsp").forward(request, response);
return "dslr";
}
else{
return "error";
}
}
}
@RequestMapping(value = "/s", method = RequestMethod.POST)
public String showHTMLResponsePOST(@ModelAttribute("dslrs") DSLR dslrs[],
@ModelAttribute("dslrErrors") HashMap<?,?> dslrErrors,
@ModelAttribute ("dslrform") DSLRForm dslrForm,
@RequestParam("id") String paramId,
@RequestParam("action") String paramAction,
@RequestParam("dslr_model") String paramModel,
@RequestParam("price") String paramPrice,
@RequestParam("description") String paramDescription,
Model model){
int iStatusCode = 0;
if(paramAction.equals("save") )
iStatusCode = saveDSLR(paramId, paramModel, paramPrice, paramDescription, dslrErrors, dslrForm); // POST
return "dslrs";
}
private int saveDSLR(String paramId,
String paramModel,
String paramPrice,
String paramDescription,
HashMap<?,?> context_dslrErrors,
DSLRForm context_dslrForm
) {
int byte0 = 1;
try {
DSLRValidaor dslrValidaor = new DSLRValidaor();
DSLRForm dslrForm = new DSLRForm();
dslrForm.setDslrId(paramId);
dslrForm.setModel(paramModel);
dslrForm.setPrice(paramPrice);
dslrForm.setDescription(paramDescription);
HashMap hashmap = dslrValidaor.Validate(dslrForm);
if(hashmap.size() > 0) {
context_dslrForm = dslrForm;
context_dslrErrors = hashmap;
byte0 = -1;
} else{
DSLRDAO planedao = new DSLRDAO();
DSLR dslr = new DSLR();
dslr.setDslrId(Integer.parseInt(paramId));
dslr.setModel(paramModel);
dslr.setPrice(Integer.parseInt(paramPrice));
dslr.setDescription(paramDescription);
planedao.update(dslr);
}
}
catch(Exception exception)
{
logger.error((new StringBuilder()).append("DSLRServlet.saveDSLR():").append(exception.getMessage()).toString());
byte0 = -1;
}
return byte0;
}
private DSLR[] getAllDslrs(){
DSLR adslrs[] = null;
try
{
DSLRDAO DSLRDAO = new DSLRDAO();
adslrs = (DSLR[])DSLRDAO.findAll();
}
catch(Exception exception)
{
logger.error((new StringBuilder()).append("PlaneServlet.getAllPlanes():").append(exception.getMessage()).toString());
}
// request.setAttribute("dslrs", adslrs);
return adslrs;
}
private HashMap<String, Object> getDSLRById(String s)
{
HashMap<String,Object> map = new HashMap<String, Object>();
DSLR dslr = null;
try {
int i = Integer.parseInt(s);
DSLRDAO DSLRDAO = new DSLRDAO();
dslr = (DSLR)DSLRDAO.findById(i);
DSLRForm dslrForm = new DSLRForm();
dslrForm.setDslrId(Integer.toString(dslr.getDslrId()));
dslrForm.setModel(dslr.getModel());
dslrForm.setPrice(Integer.toString(dslr.getPrice()));
dslrForm.setDescription(dslr.getDescription());
map.put("dslr", dslr);
map.put("dslrform", dslrForm);
map.put("dslrErrors", new HashMap());
}
catch(Exception exception)
{
logger.error((new StringBuilder()).append("DSLRServlet.getDSLRById():").append(exception.getMessage()).toString());
}
return map;
}
public void setDslrDAO(DSLRDAO dslrDAO) {
this.dslrDAO = dslrDAO;
}
public DSLRDAO getDslrDAO() {
return dslrDAO;
}
public void setDSLR(main.java.com.springapp.mvc.model.DSLR DSLR) {
dslr = DSLR;
}
public main.java.com.springapp.mvc.model.DSLR getDSLR() {
return dslr;
}
}
UPDATE1:
new mvc-dispatcher-servlet.xml:
<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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="main.java.com.springapp.mvc" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
@Autowired被放入DSLRServletController:
@Autowired
public DSLRServletController() {
this.dslrDAO = new DSLRDAO();
}
错误:
exception
javax.servlet.ServletException: Servlet.init() for servlet mvc-dispatcher threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
root cause
java.lang.IllegalStateException: Autowired annotation requires at least one argument: public main.java.com.springapp.mvc.controller.DSLRServletController()
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:243)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:976)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:598)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:517)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:458)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:138)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
出于某种原因出现了2个错误。应该更改什么才能正确设置项目?
UPDATE3
新的mvc-dispatcher-servlet.xml:
<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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="main.java.com.springapp.mvc" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="DSLR" class="main.java.com.springapp.mvc.model.DSLR" />
</beans>
除了 UPDATE1 中添加的@Autowired之外,还添加了另一个(在 DSLRServletController 中):
@Autowired
public void setDSLR(DSLR DSLR) {
dslr = DSLR;
}
UPDATE4:
返回原始错误:Could not instantiate bean class [[Lmain.java.com.springapp.mvc.model.DSLR;]
我很困惑。 出了什么问题?
答案 0 :(得分:5)
在您的控制器方法中,您已将参数用作如下所示的数组
@ModelAttribute("dslrs") DSLR dslrs[]
所以请使用像list这样的集合
@ModelAttribute("dslrs") ArrayList<DSLR> dslrs
答案 1 :(得分:4)
如果DSLR
没有默认构造函数,那么这是您将收到的错误消息:
java.lang.NoSuchMethodException: main.java.com.springapp.mvc.model.DSLR.<init>()
现在将此与您的错误消息进行比较:
java.lang.NoSuchMethodException: [Lmain.java.com.springapp.mvc.model.DSLR;.<init>()
你注意到了区别吗? [L
?该错误意味着您无法使用构造函数实例化数组,因为数组没有构造函数。这就是为什么你不能使用数组作为控制器方法的参数的原因。至少不那样。使用一个集合,你很好。
答案 2 :(得分:1)
我注意到一点点冗余。它本身不应该导致这些问题,但它可能值得探索:
您使用<context:component-scan base-package="main.java.com.springapp.mvc" >
,似乎是为了加载@Controller
- 已注释DSLRServletController
。如果是这种情况,那么就不需要在XML配置中声明名为s
的bean。您可以简单地将@Autowired
放在bean属性设置器上。或者,您可以从XML配置中删除<context:component-scan>
,并相信您对控制器的延期就足够了。
此外,尽管它可能没有相关性。如果使用@Controller
和类路径注释扫描加载某些内容,则根本不需要实现HttpServlet
。 @Controller
和Spring MVC的目的是使控制器可以是普通旧Java对象(POJO)。
最重要的是,看起来web.xml
仅导致mvc-dispatcher-servlet.xml
被加载(通过使用servlet名称作为提示),并且没有任何内容正在加载DSLRServletController-servlet.xml
。这样做的结果是,<context:component-scan base-package="main.java.com.springapp.mvc"/>
导致控制器被加载,但没有设置它的属性。要进一步清理系统,请将DSLRServletController-servlet.xml
移至mvc-dispatcher-servlet.xml
,以便通过单个配置配置弹簧上下文。
答案 3 :(得分:0)
在使用Apache Tomcat 9.0运行Spring Boot应用程序时遇到相同的问题。 现在,我已经解决了这个问题。
我评论了以下两行。 (即,无论您在此处使用过什么,只需注释并运行即可)。然后它将起作用。
@RequestMapping("/userhome")
public String userhome(Model model) {
System.out.println("inside bck...");
//List<String> colorList = colorList();`enter code here`
//model.addAttribute("theme", colorList);
//model.addAttribute("home", new UserHome());
return "userhomePage";
}
答案 4 :(得分:0)
就我而言,问题不在于没有默认构造函数。问题是在 json DTO 的字段中没有设置器,这些字段在 rest post 调用中传递给控制器。