本文整理汇总了Java中org.springframework.util.ReflectionUtils.findMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.findMethod方法的具体用法?Java ReflectionUtils.findMethod怎么用?Java ReflectionUtils.findMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.findMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invoke
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void invoke() throws Throwable {
Method methodOne = ReflectionUtils.findMethod(TargetOne.class, "methodOne");
Object proxy = new Object();
Object[] args = new Object[]{};
InvocationHandler invocationHandler = buildInvocationHandler(methodOne);
Object response = new Object();
when(clientMethodHandler.invoke(same(args))).thenReturn(response);
assertThat(invocationHandler.invoke(proxy, methodOne, args))
.isSameAs(response);
verify(clientMethodHandler).invoke(same(args));
verifyNoMoreInteractions(clientMethodHandler);
}
示例2: getGuild
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Guild getGuild(Event event) {
if (event == null) {
return null;
}
Class<? extends Event> clazz = event.getClass();
Method method;
if (!guildAccessors.containsKey(clazz)) {
method = ReflectionUtils.findMethod(clazz, "getGuild");
guildAccessors.put(clazz, method);
} else {
method = guildAccessors.get(clazz);
}
if (method != null) {
Object result = ReflectionUtils.invokeMethod(method, event);
if (result instanceof Guild) {
return (Guild) result;
}
}
return null;
}
示例3: toString
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private String toString(DataSource dataSource) {
if (dataSource == null) {
return "<none>";
} else {
try {
Field urlField = ReflectionUtils.findField(dataSource.getClass(), "url");
ReflectionUtils.makeAccessible(urlField);
return stripCredentials((String) urlField.get(dataSource));
} catch (Exception fe) {
try {
Method urlMethod = ReflectionUtils.findMethod(dataSource.getClass(), "getUrl");
ReflectionUtils.makeAccessible(urlMethod);
return stripCredentials((String) urlMethod.invoke(dataSource, (Object[])null));
} catch (Exception me){
return "<unknown> " + dataSource.getClass();
}
}
}
}
示例4: invokeMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* 调用方法,可以是一些私有方法
*
* @param target
* @param methodName
* @param args
* @return
* @throws Exception
*/
public static Object invokeMethod(Object target, String methodName, Object... args) throws Exception {
Method method = null;
// 查找对应的方法
if (args == null || args.length == 0) {
method = ReflectionUtils.findMethod(target.getClass(), methodName);
} else {
Class[] argsClass = new Class[args.length];
for (int i = 0; i < args.length; i++) {
argsClass[i] = args[i].getClass();
}
method = ReflectionUtils.findMethod(target.getClass(), methodName, argsClass);
}
ReflectionUtils.makeAccessible(method);
if (args == null || args.length == 0) {
return ReflectionUtils.invokeMethod(method, target);
} else {
return ReflectionUtils.invokeMethod(method, target, args);
}
}
示例5: JBossModulesAdapter
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public JBossModulesAdapter(ClassLoader loader) {
this.classLoader = loader;
try {
Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer");
transformer.setAccessible(true);
this.delegatingTransformer = transformer.get(loader);
if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " +
this.delegatingTransformer.getClass().getName());
}
this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
"addTransformer", ClassFileTransformer.class);
this.addTransformer.setAccessible(true);
}
catch (Exception ex) {
throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex);
}
}
示例6: invoke
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
if (invocation.getMethod().getName().equals("init")) {
Method method = ReflectionUtils
.findMethod(WebSecurityConfigurerAdapter.class, "getHttp");
ReflectionUtils.makeAccessible(method);
HttpSecurity http = (HttpSecurity) ReflectionUtils.invokeMethod(method,
invocation.getThis());
this.configurer.configure(http);
}
return invocation.proceed();
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:13,代码来源:OAuth2SsoCustomConfiguration.java
示例7: CookieRetrievingCookieGenerator
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Instantiates a new Cookie retrieving cookie generator.
* @param casCookieValueManager the cookie manager
*/
public CookieRetrievingCookieGenerator(final CookieValueManager casCookieValueManager) {
super();
final Method setHttpOnlyMethod = ReflectionUtils.findMethod(Cookie.class, "setHttpOnly", boolean.class);
if(setHttpOnlyMethod != null) {
super.setCookieHttpOnly(true);
} else {
logger.debug("Cookie cannot be marked as HttpOnly; container is not using servlet 3.0.");
}
this.casCookieValueManager = casCookieValueManager;
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:CookieRetrievingCookieGenerator.java
示例8: callMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T callMethod(String name, Object target, Object[] args, Class<?>[] argsTypes) throws Exception {
Class<?> clazz = target.getClass();
Method method = ReflectionUtils.findMethod(clazz, name, argsTypes);
if (method == null)
throw new IllegalArgumentException("Cannot find method '" + method + "' in the class hierarchy of "
+ target.getClass());
method.setAccessible(true);
return (T) ReflectionUtils.invokeMethod(method, target, args);
}
示例9: invoke_withWrongTargetMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void invoke_withWrongTargetMethod() throws Throwable {
Method methodOne = ReflectionUtils.findMethod(TargetOne.class, "methodOne");
Method methodTwo = ReflectionUtils.findMethod(TargetOne.class, "methodTwo");
Object proxy = new Object();
Object[] args = new Object[]{};
InvocationHandler invocationHandler = buildInvocationHandler(methodOne);
assertThatThrownBy(()-> invocationHandler.invoke(proxy, methodTwo, args))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Couldn't find a MethodHandler for the method");
verifyZeroInteractions(clientMethodHandler);
}
示例10: requestMany
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void requestMany() throws Exception {
Method m = ReflectionUtils.findMethod(ServiceInfoTest.class, "requestMany", null);
ServiceMethodInfo serviceMethodInfo = new ServiceMethodInfo(m);
assertThat(Flux.class).isAssignableFrom(serviceMethodInfo.getReturnType().resolve());
assertThat(String.class).isAssignableFrom(serviceMethodInfo.getParameterType().resolve());
}
示例11: getMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Method getMethod(MethodInvocation invocation, Object object) {
Method method = invocation.getMethod();
return ReflectionUtils
.findMethod(object.getClass(), method.getName(), method.getParameterTypes());
}
示例12: multipleParameters
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test
public void multipleParameters() throws Exception {
Method m = ReflectionUtils.findMethod(ServiceInfoTest.class, "oneWayMultipleParameters", null);
ServiceMethodInfo serviceMethodInfo = new ServiceMethodInfo(m);
assertThat(String.class).isAssignableFrom(serviceMethodInfo.getParameterType().resolve());
}
示例13: readObject
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
inputStream.defaultReadObject();
Method method = ReflectionUtils.findMethod(this.provider.getType().getClass(), this.methodName);
this.result = ReflectionUtils.invokeMethod(method, this.provider.getType());
}
示例14: multiplePayloads
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void multiplePayloads() throws Exception {
Method m = ReflectionUtils.findMethod(ServiceInfoTest.class, "multiplePayloadAnnotations", null);
ServiceMethodInfo serviceMethodInfo = new ServiceMethodInfo(m);
}
示例15: CookieCsrfTokenRepository
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
public CookieCsrfTokenRepository() {
this.setHttpOnlyMethod = ReflectionUtils.findMethod(Cookie.class, "setHttpOnly", boolean.class);
if (this.setHttpOnlyMethod != null) {
this.cookieHttpOnly = true;
}
}