![]() ![]() String hashType 'md5' Method method (hashType + 'Hex', String. And you should pass something (better null) as a first argument to invoke a static method. IEngine app2 = (IEngine) c2.newInstance() Īssert.equals(s1,s2,"Outputs from somejar-1.0 and somejar-2.0 did not match, perhaps somejar-2. You should add an argument type as a second argument in getDeclaredMethod. If I remove Valid annotation, request goes through but Bean Validations are ignored. parameterType which is the array of parameter type for the specified method. methodName which is the Method to be get. IEngine app1 = (IEngine) c1.newInstance() I have a Rest service (SpringBoot application) that throws an exception if I add Valid annotation to Rest Controller method that process requests. Syntax: public Method getMethod (String methodName, Class parameterType) throws NoSuchMethodException, SecurityException. ![]() public static void main(String args) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException ) Ĭlass c1 = loader1.loadClass(".EngineV1") Ĭlass c2 = loader2.loadClass(".EngineV2") So I created an interface with 2 implementation classes, both classes have a run method which makes use of common apis one will use somejar-1.0.0-SNAPSHOT.jar and the other will use somejar-2.0.0-SNAPSHOT.jar by explicitly calling ClassLoader. In Java, ('bar') declares a checked exception of type NoSuchMethodException (among others). For example, if the receivers class has testMethod(Foo) defined, the following fails: receiver.getClass().getMethod('testMethod', FooSubclass.class). I'm trying to call 2 different versions of the same dependency library ( jars) within a top level Main class. However, when one of the parameters is a subclass of one of the supported types for the method, the reflection API throws a NoSuchMethodException.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |