For file upload I am trying to inject and use a Validator in my Spring Controller like this:
@RestController
@RequestMapping(\"/api\")
public class FileControlle
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.
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;