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

前端 未结 2 2087
终归单人心
终归单人心 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.

提交回复
热议问题