java.lang.IllegalArgumentException异常解决

在maven项目中测试代码的时候,碰到java.lang.IllegalArgumentException异常:

严重: Servlet.service() for servlet [e3-manager] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: No converter found for return value of type: class cn.e3mall.pojo.TbItem] with root cause

java.lang.IllegalArgumentException: No converter found for return value of type: class cn.e3mall.pojo.TbItem

    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:178)

    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:153)

    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:165)

    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80)

    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)

    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)

    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)

    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)

    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)

    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)

    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)

    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)

eclipse运行异常截图:

    问题原因:是因为springmvc默认是没有对象转换成json的转换器的,需要手动添加jackson依赖,而maven中的json的 jar 包没有加载到项目中去,导致这个异常出现

解决方法:

在web的pom.xml中添加以下依赖

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.5</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.8.5</version>
</dependency>

默认把json的jar包添加到项目中。

but 添加之后,我的整个web项目都报错了,这就很尴尬尴尬


还好有大神指点,找到我的maven中的settings.xml文件,添加国内镜像(因为maven默认的是国外的镜像)


<mirror>
            <id>cn_central</id>
            <name>cn_central</name>
            <mirrorOf>central</mirrorOf>
            <url>http://repo1.maven.org/maven2/</url>
</mirror>

然后再在web中pom.xml文件中,按住Ctrl键,点击鼠标左键,就会有链接:

<groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.5</version>
</dependency>

说明配置好了(真的是不容易啊)

注:如果maven更新的太慢,可以打开网页,输入“鸠摩智”就会变快,很神奇!!!

测试运行结果:



发布了35 篇原创文章 · 获赞 36 · 访问量 8万+
展开阅读全文

java.lang.IllegalArgumentException求大神帮帮忙!!!

08-24

异常提示:Servlet.service() for servlet [dispatcher] in context with path [/comsed1] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Bean object must not be null; nested exception is java.lang.IllegalArgumentException: Bean object must not be null] with root cause java.lang.IllegalArgumentException: Bean object must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:213) at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:202) at org.springframework.beans.BeanWrapperImpl.<init>(BeanWrapperImpl.java:151) at org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper.<init>(DirectFieldAccessFallbackBeanWrapper.java:35) at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.getId(JpaMetamodelEntityInformation.java:117) at org.springframework.data.repository.core.support.AbstractEntityInformation.isNew(AbstractEntityInformation.java:51) at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.isNew(JpaMetamodelEntityInformation.java:196) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:376) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:405) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:390) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:344) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy136.save(Unknown Source) at iot.service.ProductMasterService.modifyProductMaster(ProductMasterService.java:32) at iot.controller.productMasterController.modifyProductMaster(productMasterController.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 代码部分: @RequestMapping(value = "modifyProductMasterInit") public String modifyProductMasterInit(@RequestParam("productId") String productId,Model model){ // Iterable<ProductMaster> productMasterList = productMasterDAO.findByProductId(productId); // model.addAttribute("productMasterList", productMasterList); ProductMaster productMaster = this.productMasterService.findByProductId(productId); model.addAttribute("productMaster", productMaster); return "productMaster/Pro_Master_modify"; } @RequestMapping(value = "modifyProductMaster") public String modifyProductMaster(ProductMaster productMaster,@RequestParam("productId") String productId){ ProductMaster productMasterOld = this.productMasterService.findByProductId(productId);//经断点调试productMasterOld为空 try { BeanUtils.copyProperties(productMaster, productMasterOld); } catch (Exception e) { e.printStackTrace(); } this.productMasterService.modifyProductMaster(productMasterOld); return "redirect:/productMaster/loadProductMaster"; } Service方法: @Service public class ProductMasterService { @Autowired(required = false) private ProductMasterDAO productMasterDAO; public void addproductMaster(ProductMaster productMaster) { this.productMasterDAO.save(productMaster); } public ProductMaster findByProductId(String productId) { return this.productMasterDAO.findByProductId(productId); } public void modifyProductMaster(ProductMaster productMaster) { this.productMasterDAO.save(productMaster); } } ProductMasterDAO部分: public interface ProductMasterDAO extends PagingAndSortingRepository<ProductMaster, String>,JpaSpecificationExecutor<ProductMaster>{ @Query("SELECT p FROM ProductMaster p WHERE p.productId = ?1") public ProductMaster findByProductId(String productId); } 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览