qq_27289653
血色蒼穹
采纳率0%
2016-08-24 07:46

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

50

异常提示: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.(BeanWrapperImpl.java:151)
at org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper.(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 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,JpaSpecificationExecutor{

@Query("SELECT p FROM ProductMaster p WHERE p.productId = ?1")
public ProductMaster findByProductId(String productId);

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • u013829202 觅夜的黑 5年前

    IllegalArgument是参数异常。 你debug一下,找找。 我只是一个打酱油路过的围观群众

    点赞 1 评论 复制链接分享
  • baidu_34046383 星之火燎原 5年前

    ProductMasterDAO需要在application配置,另外,ProductMasterService 引用ProductMasterDAO要提供set方法,希望采纳

    点赞 1 评论 复制链接分享
  • dear_Alice_moon _明月 3年前

    main函数是否运行?

     还有,就是jdk版本要与 Spring的jar包相匹配。
    

    可以参考文章: https://blog.csdn.net/fpxty/article/details/72675040

    点赞 评论 复制链接分享
  • zy_281870667 Bug开发攻城狮 5年前

    ProductMasterService 和 ProductMasterDAO,你都得加上@Component注解

    点赞 评论 复制链接分享