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

异常提示: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个回答

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

dear_Alice_moon
_明月 回复qq_27289653: 可以参考着2篇文章: http://www.cnblogs.com/zhanyao/p/4409231.html , https://blog.csdn.net/u010513756/article/details/51597934
接近 2 年之前 回复
qq_27289653
血色蒼穹 ProductMasterDAO是继承spring data jpa给的repository,还有你说的ProductMasterService 引用ProductMasterDAO要提供set方法,能说的具体点吗,我不太清楚
接近 4 年之前 回复

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

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

zy_281870667
Bug开发攻城狮 回复qq_27289653: 你的PagingAndSortingRepository或者PagingAndSortingRepository的配置有问题,它们在注入的时候没注入成功
接近 4 年之前 回复
qq_27289653
血色蒼穹 ProductMasterService 我是加了@Service的,而ProductMasterDAO加不加都一样的,Spring data jpa 的配置会自动解析装配的,而且加了也一样的
接近 4 年之前 回复

main函数是否运行?

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

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问