List of usage examples for org.springframework.core.annotation AnnotationUtils findAnnotation
@Nullable public static <A extends Annotation> A findAnnotation(Class<?> clazz, @Nullable Class<A> annotationType)
From source file:nats.client.spring.AnnotationConfigBeanPostProcessor.java
@Override public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException { final Class<?> clazz = bean.getClass(); for (final Method method : clazz.getMethods()) { final Subscribe annotation = AnnotationUtils.findAnnotation(method, Subscribe.class); if (annotation != null) { final Class<?>[] parameterTypes = method.getParameterTypes(); if (parameterTypes.length != 1 || !parameterTypes[0].equals(Message.class)) { throw new BeanInitializationException(String.format( "Method '%s' on bean with name '%s' must have a single parameter of type %s when using the @%s annotation.", method.toGenericString(), beanName, Message.class.getName(), Subscribe.class.getName())); }//from w ww. j a v a2 s . c o m nats.subscribe(annotation.value()).addMessageHandler(new MessageHandler() { @Override public void onMessage(Message message) { try { method.invoke(bean, message); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { final Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } throw new RuntimeException(targetException); } } }); } } return bean; }
From source file:com.mmj.app.common.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;// w w w . ja v a2 s . c o m } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":-1,\"message\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); if (InvokeTypeTools.isAjax(request)) { return createJsonMav(",?!", ResultCode.ERROR, e.getMessage()); } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false"); mav.setViewName("error"); return mav; }
From source file:com.frank.search.solr.server.support.SolrClientUtils.java
/** * Resolve solr core/collection name for given type. * * @param type/* ww w . j a va 2 s . c o m*/ * @return empty string if {@link SolrDocument} not present or * {@link SolrDocument#solrCoreName()} is blank. * @since 1.1 */ public static String resolveSolrCoreName(Class<?> type) { SolrDocument annotation = AnnotationUtils.findAnnotation(type, SolrDocument.class); if (annotation != null && StringUtils.isNotBlank(annotation.solrCoreName())) { return annotation.solrCoreName(); } return ""; }
From source file:com.stehno.sjdbcx.support.SqlResolver.java
/** * Uses the Sql and JdbcRepository annotations to resolve the SQL string to be used. * * @param prototype the repository prototype class * @param method the method to resolve SQL for * @return the String of SQL//from w w w. j a v a 2 s . c om */ public String resolve(final Class prototype, final Method method) { final JdbcRepository jdbcAnno = AnnotationUtils.findAnnotation(prototype, JdbcRepository.class); final Sql sqlAnno = AnnotationUtils.getAnnotation(method, Sql.class); if (shouldLookupSql(jdbcAnno, sqlAnno)) { final String sqlKey = StringUtils.hasLength(sqlAnno.value()) ? sqlAnno.value() : method.getName().toLowerCase(); final Resource resource = determineResolverResource(prototype, jdbcAnno); final String sql = resolve(resource).getProperty(sqlKey); log.debug("Resolved SQL ({}) for repository ({}) from resource ({}) property ({})", sql, prototype, resource, sqlKey); return sql; } else { return sqlAnno.value(); } }
From source file:org.jdal.aop.SerializableProxyAdvisor.java
/** * Checks for {@link SerializableProxy} anntation at type level. * @return true if annotation found.//from www. j a va 2 s .c o m */ @Override public boolean matches(Class<?> clazz) { SerializableProxy ann = AnnotationUtils.findAnnotation(clazz, SerializableProxy.class); if (ann != null && !SerializableAopProxy.class.isAssignableFrom(clazz)) { String beanName = ProxyCreationContext.getCurrentProxiedBeanName(); if (beanName != null && !beanName.startsWith(SerializableProxyUtils.TARGET_NAME_PREFIX)) { configureReference(ann, beanName); return true; } } return false; }
From source file:com.github.springfox.loader.SpringfoxLoader.java
EnableSpringfox getAnnotation(ApplicationContext applicationContext) {
Object bean = getBeanWithAnnotation(applicationContext);
return AnnotationUtils.findAnnotation(bean.getClass(), EnableSpringfox.class);
}
From source file:org.vaadin.spring.test.VaadinTestExecutionListener.java
private boolean notAnnotatedWithVaadinAppConfiguration(TestContext testContext) { return AnnotationUtils.findAnnotation(testContext.getTestClass(), VaadinAppConfiguration.class) == null; }
From source file:it.cosenonjaviste.alfresco.annotations.processors.runtime.WebScriptConfigurer.java
@Override protected void processBeanDefinition(ConfigurableListableBeanFactory beanFactory, BeanDefinition bd, String beanClassName, String definitionName) throws FatalBeanException { if (beanFactory instanceof DefaultListableBeanFactory) { DefaultListableBeanFactory factory = (DefaultListableBeanFactory) beanFactory; try {// w ww. jav a 2 s. co m final WebScript webScript = AnnotationUtils.findAnnotation(Class.forName(beanClassName), WebScript.class); if (webScript != null) { String beanName = webScript.value(); if (StringUtils.hasText(beanName)) { final String webScriptName = "webscript." + beanName + "." + webScript.method().toString().toLowerCase(); factory.removeBeanDefinition(definitionName); factory.registerBeanDefinition(webScriptName, bd); } else { throw new FatalBeanException( String.format("%s is @WebScript annotated, but no value set.", beanClassName)); } } } catch (ClassNotFoundException e) { logger.warn(String.format( "ClassNotFoundException while searching for ChildOf annotation on bean name '%s' of type '%s'. This error is expected on Alfresco Community 4.2.c. for some classes in package 'org.alfresco.repo'", definitionName, beanClassName)); } } else { logger.error(String.format( "Unable to register '%s' as webscript because beanFactory is not instance of 'DefaultListableBeanFactory'", definitionName)); } }
From source file:com.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java
@Override public void beforeTestClass(TestContext testContext) throws Exception { Logback annotation = AnnotationUtils.findAnnotation(testContext.getTestClass(), Logback.class); if (annotation != null) { String location = processLocation(testContext.getTestClass(), annotation.value()); LogbackConfigurer.initLogging(location); }/*from ww w . jav a 2s. co m*/ }
From source file:fr.norad.jaxrs.oauth2.core.application.GrantTypeBasedResourceComparator.java
@Autowired @OauthResource// www .j a v a 2 s .co m void initGrantToServiceClassMapping(List<TargetClassAware> services) { for (TargetClassAware service : services) { Grants annotation = AnnotationUtils.findAnnotation(service.getTargetClass(), Grants.class); if (annotation != null) { grantHandlerClasses.put(annotation.value(), service.getTargetClass()); } } }