我正在尝试将.class文件加载到Spring项目中。我试过了:
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
ResourcePatternResolver resolver = (ResourcePatternResolver)context;
Resource[] res = resolver.getResources("classpath*:/opt/validation/*.class");
resolver.getClassLoader().loadClass("ValidateProcessor");
但是我收到错误Root cause of ServletException.
java.lang.ClassNotFoundException: ValidateProcessor
文件ValidateProcessor.class存在于该目录中,但未找到。您能给我一些建议如何解决此问题吗?
您必须使用完整的合格类名。如果该类位于包opt.validation
中,则应加载:
resolver.getClassLoader().loadClass("opt.validation.ValidateProcessor");