spring No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.mo
還是在學習spring mvc 過程中學習頁面,頁面到 controller 中引數傳遞的時候在form表單提交 轉為物件的時候報的錯。
type Exception report
message Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.slj.model.Student]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.model.Student.<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: Failed to instantiate [com.slj.model.Student]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.model.Student.<init>() org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.slj.model.Student]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.slj.model.Student.<init>() org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107) org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:137) org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:80) org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106) org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78) org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871) javax.servlet.http.HttpServlet.service(HttpServlet.java:646) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)分析後,它說我沒有model的無參建構函式,但是我傳遞過來的有參的。這就需要討論實現原理了。
首先感覺是接受頁面的parameter 可能name 不和model 的屬性不匹配,所以就相當於沒有該model的引數傳遞過來,呼叫該model的無參構造方法。由於bean 是在未呼叫前就已經建立的,所以建立bean 時候考慮了這樣的問題,所以必須有為空的建構函式。
相關文章
- nested exception is java.lang.NoSuchMethodException: 實體類.()ExceptionJava
- Default copy constructor does not call correct base(轉) constructorStruct
- nested exception is IncompleteElementException: Could not find parameter mapException
- Initialization of bean failed; nested exception is java.lang.StackOverflowErrorBeanAIExceptionJavaError
- nested exception is java.lang.NoSuchFieldError: FAIL_ON_SYMBOL_HASH_OVERFLOWExceptionJavaErrorAISymbol
- dubbo和spring結合報錯 Invocation of init method failed; nested exception is java.lang.IllegalArgumentExceSpringAIExceptionJava
- 使用URLClassLoader報錯not class found exceptionException
- bug solved | export 'default' was not found in 'xxx'Export
- vuex報錯 vuex__WEBPACK_IMPORTED_MODULE_1__.default.store is not a constructorVueWebImportStruct
- javax.faces.FacesException: Nested form found on the page. The form action elemeJavaExceptionORM
- [Symfony\Component\Debug\Exception\FatalThrowableError] Class 'LaravelLocalization' not foundExceptionErrorLaravel
- { “code”: “-1”, “msg”: “nested exception is org.apache.ibatis.exceptions.TooManyResultsException: ExExceptionApacheBATOOM
- 報錯:nested exception is java.lang.NoClassDefFoundError: org/fusesource/hawtbuf/UTF8BufferExceptionJavaError
- nested exception is javax.validation.ValidationException錯誤解決思路ExceptionJava
- nested exception is org.hibernate.InvalidMappingException: Could not parse mappiExceptionAPP
- HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGramHTTPAIExceptionSpringFrameworkJDBCSQL
- nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379ExceptionRedislocalhost
- Symfony\Component\Debug\Exception\FatalThrowableError Class 'Lcobucci\JWT\Builder' not foundExceptionErrorJWTUI
- OGG - No Valid Default Archive Destination Directory Found for Thread #Hivethread
- java.lang.NoSuchMethodException: $ProxyJavaException
- Unknown column ‘name‘ in ‘field list‘ ; bad SQL grammar []; nested exception is com.mysql.jdbc.excepExceptionMySqlJDBC
- Spring - constructor-arg和property的使用示例SpringStruct
- n [Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoAIExceptionRPC
- 簡易版的 Spring 之如何實現 Constructor 注入SpringStruct
- 記一次android app啟動錯誤 Error running :Default Activity not foundAndroidAPPError
- 解決bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 無效字元SQLExceptionJavaError字元
- ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00909: 引數個數無效SQLExceptionJavaError
- Prototype/ConstructorStruct
- JavaScript constructorJavaScriptStruct
- nested loop心得OOP
- spring中通過constructor來注入引數的四種方式SpringStruct
- get_constructorStruct
- constructor和superStruct
- TypeError: SizeOnlySource is not a constructorErrorStruct
- Lombok 之 ConstructorLombokStruct
- spring boot 服務啟動時no active profile set, falling back to default profiles: default的問題Spring Boot
- Spring Cloud Gateway自定義異常處理Exception HandlerSpringCloudGatewayException
- Angular 2 constructor & ngOnInitAngularStructGo