Java Code Examples for org.springframework.core.annotation.AnnotatedElementUtils#findMergedAnnotationAttributes()
The following examples show how to use
org.springframework.core.annotation.AnnotatedElementUtils#findMergedAnnotationAttributes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BeanAnnotationHelper.java From spring-analysis-note with MIT License | 6 votes |
public static String determineBeanNameFor(Method beanMethod) { String beanName = beanNameCache.get(beanMethod); if (beanName == null) { // By default, the bean name is the name of the @Bean-annotated method beanName = beanMethod.getName(); // Check to see if the user has explicitly set a custom bean name... AnnotationAttributes bean = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Bean.class, false, false); if (bean != null) { String[] names = bean.getStringArray("name"); if (names.length > 0) { beanName = names[0]; } } beanNameCache.put(beanMethod, beanName); } return beanName; }
Example 2
Source File: BeanAnnotationHelper.java From java-technology-stack with MIT License | 6 votes |
public static String determineBeanNameFor(Method beanMethod) { String beanName = beanNameCache.get(beanMethod); if (beanName == null) { // By default, the bean name is the name of the @Bean-annotated method beanName = beanMethod.getName(); // Check to see if the user has explicitly set a custom bean name... AnnotationAttributes bean = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Bean.class, false, false); if (bean != null) { String[] names = bean.getStringArray("name"); if (names.length > 0) { beanName = names[0]; } } beanNameCache.put(beanMethod, beanName); } return beanName; }
Example 3
Source File: BeanAnnotationHelper.java From spring-analysis-note with MIT License | 5 votes |
public static boolean isScopedProxy(Method beanMethod) { Boolean scopedProxy = scopedProxyCache.get(beanMethod); if (scopedProxy == null) { AnnotationAttributes scope = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Scope.class, false, false); scopedProxy = (scope != null && scope.getEnum("proxyMode") != ScopedProxyMode.NO); scopedProxyCache.put(beanMethod, scopedProxy); } return scopedProxy; }
Example 4
Source File: SpringTransactionAnnotationParser.java From spring-analysis-note with MIT License | 5 votes |
@Override @Nullable public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { // 解析事务注解的属性 AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( element, Transactional.class, false, false); if (attributes != null) { return parseTransactionAnnotation(attributes); } else { return null; } }
Example 5
Source File: MergedSqlConfig.java From spring-analysis-note with MIT License | 5 votes |
/** * Construct a {@code MergedSqlConfig} instance by merging the configuration * from the supplied local (potentially method-level) {@code @SqlConfig} annotation * with class-level configuration discovered on the supplied {@code testClass}. * <p>Local configuration overrides class-level configuration. * <p>If the test class is not annotated with {@code @SqlConfig}, no merging * takes place and the local configuration is used "as is". */ MergedSqlConfig(SqlConfig localSqlConfig, Class<?> testClass) { Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null"); Assert.notNull(testClass, "testClass must not be null"); // Get global attributes, if any. AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( testClass, SqlConfig.class.getName(), false, false); // Override global attributes with local attributes. if (attributes != null) { for (String key : attributes.keySet()) { Object value = AnnotationUtils.getValue(localSqlConfig, key); if (value != null) { // Is the value explicit (i.e., not a 'default')? if (!value.equals("") && value != TransactionMode.DEFAULT && value != ErrorMode.DEFAULT) { attributes.put(key, value); } } } } else { // Otherwise, use local attributes only. attributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false); } this.dataSource = attributes.getString("dataSource"); this.transactionManager = attributes.getString("transactionManager"); this.transactionMode = getEnum(attributes, "transactionMode", TransactionMode.DEFAULT, TransactionMode.INFERRED); this.encoding = attributes.getString("encoding"); this.separator = getString(attributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR); this.commentPrefix = getString(attributes, "commentPrefix", ScriptUtils.DEFAULT_COMMENT_PREFIX); this.blockCommentStartDelimiter = getString(attributes, "blockCommentStartDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER); this.blockCommentEndDelimiter = getString(attributes, "blockCommentEndDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER); this.errorMode = getEnum(attributes, "errorMode", ErrorMode.DEFAULT, ErrorMode.FAIL_ON_ERROR); }
Example 6
Source File: BootstrapUtils.java From spring-analysis-note with MIT License | 5 votes |
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass) throws Exception { ClassLoader classLoader = BootstrapUtils.class.getClassLoader(); AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false); if (attributes != null) { return ClassUtils.forName(DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader); } return ClassUtils.forName(DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader); }
Example 7
Source File: MetaAnnotationUtils.java From spring-analysis-note with MIT License | 5 votes |
public AnnotationDescriptor(Class<?> rootDeclaringClass, Class<?> declaringClass, @Nullable Annotation composedAnnotation, T annotation) { Assert.notNull(rootDeclaringClass, "'rootDeclaringClass' must not be null"); Assert.notNull(annotation, "Annotation must not be null"); this.rootDeclaringClass = rootDeclaringClass; this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( rootDeclaringClass, annotation.annotationType().getName(), false, false); Assert.state(attributes != null, "No annotation attributes"); this.annotationAttributes = attributes; }
Example 8
Source File: BeanAnnotationHelper.java From java-technology-stack with MIT License | 5 votes |
public static boolean isScopedProxy(Method beanMethod) { Boolean scopedProxy = scopedProxyCache.get(beanMethod); if (scopedProxy == null) { AnnotationAttributes scope = AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Scope.class, false, false); scopedProxy = (scope != null && scope.getEnum("proxyMode") != ScopedProxyMode.NO); scopedProxyCache.put(beanMethod, scopedProxy); } return scopedProxy; }
Example 9
Source File: SpringTransactionAnnotationParser.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( element, Transactional.class, false, false); if (attributes != null) { return parseTransactionAnnotation(attributes); } else { return null; } }
Example 10
Source File: MergedSqlConfig.java From java-technology-stack with MIT License | 5 votes |
/** * Construct a {@code MergedSqlConfig} instance by merging the configuration * from the supplied local (potentially method-level) {@code @SqlConfig} annotation * with class-level configuration discovered on the supplied {@code testClass}. * <p>Local configuration overrides class-level configuration. * <p>If the test class is not annotated with {@code @SqlConfig}, no merging * takes place and the local configuration is used "as is". */ MergedSqlConfig(SqlConfig localSqlConfig, Class<?> testClass) { Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null"); Assert.notNull(testClass, "testClass must not be null"); // Get global attributes, if any. AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( testClass, SqlConfig.class.getName(), false, false); // Override global attributes with local attributes. if (attributes != null) { for (String key : attributes.keySet()) { Object value = AnnotationUtils.getValue(localSqlConfig, key); if (value != null) { // Is the value explicit (i.e., not a 'default')? if (!value.equals("") && value != TransactionMode.DEFAULT && value != ErrorMode.DEFAULT) { attributes.put(key, value); } } } } else { // Otherwise, use local attributes only. attributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false); } this.dataSource = attributes.getString("dataSource"); this.transactionManager = attributes.getString("transactionManager"); this.transactionMode = getEnum(attributes, "transactionMode", TransactionMode.DEFAULT, TransactionMode.INFERRED); this.encoding = attributes.getString("encoding"); this.separator = getString(attributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR); this.commentPrefix = getString(attributes, "commentPrefix", ScriptUtils.DEFAULT_COMMENT_PREFIX); this.blockCommentStartDelimiter = getString(attributes, "blockCommentStartDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER); this.blockCommentEndDelimiter = getString(attributes, "blockCommentEndDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER); this.errorMode = getEnum(attributes, "errorMode", ErrorMode.DEFAULT, ErrorMode.FAIL_ON_ERROR); }
Example 11
Source File: BootstrapUtils.java From java-technology-stack with MIT License | 5 votes |
private static Class<?> resolveDefaultTestContextBootstrapper(Class<?> testClass) throws Exception { ClassLoader classLoader = BootstrapUtils.class.getClassLoader(); AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false); if (attributes != null) { return ClassUtils.forName(DEFAULT_WEB_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader); } return ClassUtils.forName(DEFAULT_TEST_CONTEXT_BOOTSTRAPPER_CLASS_NAME, classLoader); }
Example 12
Source File: MetaAnnotationUtils.java From java-technology-stack with MIT License | 5 votes |
public AnnotationDescriptor(Class<?> rootDeclaringClass, Class<?> declaringClass, @Nullable Annotation composedAnnotation, T annotation) { Assert.notNull(rootDeclaringClass, "'rootDeclaringClass' must not be null"); Assert.notNull(annotation, "Annotation must not be null"); this.rootDeclaringClass = rootDeclaringClass; this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( rootDeclaringClass, annotation.annotationType().getName(), false, false); Assert.state(attributes != null, "No annotation attributes"); this.annotationAttributes = attributes; }
Example 13
Source File: MergedSqlConfig.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Construct a {@code MergedSqlConfig} instance by merging the configuration * from the supplied local (potentially method-level) {@code @SqlConfig} annotation * with class-level configuration discovered on the supplied {@code testClass}. * <p>Local configuration overrides class-level configuration. * <p>If the test class is not annotated with {@code @SqlConfig}, no merging * takes place and the local configuration is used "as is". */ MergedSqlConfig(SqlConfig localSqlConfig, Class<?> testClass) { Assert.notNull(localSqlConfig, "Local @SqlConfig must not be null"); Assert.notNull(testClass, "testClass must not be null"); // Get global attributes, if any. AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, SqlConfig.class.getName(), false, false); // Override global attributes with local attributes. if (attributes != null) { for (String key : attributes.keySet()) { Object value = AnnotationUtils.getValue(localSqlConfig, key); if (value != null) { // Is the value explicit (i.e., not a 'default')? if (!value.equals("") && (value != TransactionMode.DEFAULT) && (value != ErrorMode.DEFAULT)) { attributes.put(key, value); } } } } else { // Otherwise, use local attributes only. attributes = AnnotationUtils.getAnnotationAttributes(localSqlConfig, false, false); } this.dataSource = attributes.getString("dataSource"); this.transactionManager = attributes.getString("transactionManager"); this.transactionMode = getEnum(attributes, "transactionMode", TransactionMode.DEFAULT, TransactionMode.INFERRED); this.encoding = attributes.getString("encoding"); this.separator = getString(attributes, "separator", ScriptUtils.DEFAULT_STATEMENT_SEPARATOR); this.commentPrefix = getString(attributes, "commentPrefix", ScriptUtils.DEFAULT_COMMENT_PREFIX); this.blockCommentStartDelimiter = getString(attributes, "blockCommentStartDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_START_DELIMITER); this.blockCommentEndDelimiter = getString(attributes, "blockCommentEndDelimiter", ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER); this.errorMode = getEnum(attributes, "errorMode", ErrorMode.DEFAULT, ErrorMode.FAIL_ON_ERROR); }
Example 14
Source File: MetaAnnotationUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
public AnnotationDescriptor(Class<?> rootDeclaringClass, Class<?> declaringClass, Annotation composedAnnotation, T annotation) { Assert.notNull(rootDeclaringClass, "rootDeclaringClass must not be null"); Assert.notNull(annotation, "annotation must not be null"); this.rootDeclaringClass = rootDeclaringClass; this.declaringClass = declaringClass; this.composedAnnotation = composedAnnotation; this.annotation = annotation; this.annotationAttributes = AnnotatedElementUtils.findMergedAnnotationAttributes(rootDeclaringClass, annotation.annotationType().getName(), false, false); }
Example 15
Source File: MockServerContainerContextCustomizerFactory.java From spring-analysis-note with MIT License | 4 votes |
private static boolean isAnnotatedWithWebAppConfiguration(Class<?> testClass) { return (AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false) != null); }
Example 16
Source File: MockServerContainerContextCustomizerFactory.java From java-technology-stack with MIT License | 4 votes |
private static boolean isAnnotatedWithWebAppConfiguration(Class<?> testClass) { return (AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false) != null); }