Can not set field to com.sun.proxy.$Proxy

前端 未结 2 2085
终归单人心
终归单人心 2021-02-13 07:05

For file upload I am trying to inject and use a Validator in my Spring Controller like this:

@RestController
@RequestMapping(\"/api\")
public class FileControlle         


        
相关标签:
2条回答
  • 2021-02-13 07:25

    Can not set 'FileValidator' field 'FileController.validator' to 'com.sun.proxy.$Proxy101'

    FileValidator is a class, not an interface.

    com.sun.proxy.$Proxy101 is an interface proxy, not a class proxy.

    There are two main ways to solve this. Either inject the validator via an interface, e.g:

    @Autowired @Qualifier("fileValidator")
    private Validator fileValidator;
    

    or enable class-proxies, e.g:

    @SpringBootApplication
    @EnableAspectJAutoProxy(proxyTargetClass = true)
    public class Application {
    

    Those are just examples, there will be other ways to implement those two solutions.

    0 讨论(0)
  • 2021-02-13 07:48

    Autowire the interface of FileValidator(class) in your class FileController. Doing this will not require you to specify @Qualifier as mentioned below:

    @Autowired
    IFileValidator filevalidator;
    
    0 讨论(0)
提交回复
热议问题