热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

annotationjava数组_JavaAnnotationAttributes.getAnnotationArray方法代码示例

importorg.springframework.core.annotation.AnnotationAttributes;导入方法依赖的package包类privateMapf

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类

private Map findMyBatisBeanDefinitions() {

String[] enumsLocations = attributes.getStringArray(Constant.ENUMS_LOCATIONS_ATTRIBUTE_NAME);

String[] basePackages = attributes.getStringArray(Constant.BASE_PACKAGES_ATTRIBUTE_NAME);

AnnotationAttributes[] plugins = attributes.getAnnotationArray(Constant.PLUGINS_ATTRIBUTE_NAME);

if (ArrayUtils.isEmpty(enumsLocations)) {

enumsLocations = findDefaultPackage(metadata);

}

if (ArrayUtils.isEmpty(basePackages)) {

basePackages = findDefaultPackage(metadata);

}

Map beanDefinitions &#61; new HashMap<>(16);

BeanDefinitionBuilder sqlSessionFactoryBean &#61; BeanDefinitionBuilder.genericBeanDefinition(SqlSessionFactoryBean.class);

if (useFlyway) {

sqlSessionFactoryBean.addDependsOn(Constant.FLYWAY_BEAN_NAME);

}

sqlSessionFactoryBean.addPropertyReference("dataSource", Constant.DATA_SOURCE_BEAN_NAME);

sqlSessionFactoryBean.addPropertyValue("mapperLocations", "classpath*:/META-INF/mybatis/**/*Mapper.xml");

sqlSessionFactoryBean.addPropertyValue("configLocation", "classpath:/META-INF/mybatis/mybatis.xml");

TypeHandlerScanner scanner &#61; new TypeHandlerScanner();

sqlSessionFactoryBean.addPropertyValue("typeHandlers", scanner.find(StringUtils.join(enumsLocations, ",")));

List pluginsList &#61; new ArrayList<>(plugins.length);

List> clazz &#61; new ArrayList<>(plugins.length);

for (AnnotationAttributes plugin : plugins) {

Class extends Interceptor> pluginClass &#61; plugin.getClass("value");

AnnotationAttributes[] params &#61; plugin.getAnnotationArray("params");

clazz.add(pluginClass);

Interceptor interceptor &#61; BeanUtils.instantiate(pluginClass);

BeanWrapper beanWrapper &#61; new BeanWrapperImpl(interceptor);

for (AnnotationAttributes param : params) {

String key &#61; param.getString("key");

String value &#61; param.getString("value");

PropertyDescriptor descriptor &#61; beanWrapper.getPropertyDescriptor(key);

Method writeMethod &#61; descriptor.getWriteMethod();

Method readMethod &#61; descriptor.getReadMethod();

writeMethod.setAccessible(true);

try {

Class> returnType &#61; readMethod.getReturnType();

Object valueObject &#61; value;

if (Integer.class.equals(returnType) || int.class.equals(returnType)) {

valueObject &#61; Integer.valueOf(value);

} else if (Long.class.equals(returnType) || long.class.equals(returnType)) {

valueObject &#61; Long.valueOf(value);

} else if (Boolean.class.equals(returnType) || boolean.class.equals(returnType)) {

valueObject &#61; Boolean.valueOf(value);

} else if (Double.class.equals(returnType) || double.class.equals(returnType)) {

valueObject &#61; Double.valueOf(value);

}

writeMethod.invoke(interceptor, valueObject);

} catch (Exception e) {

e.printStackTrace();

}

}

pluginsList.add(interceptor);

}

if (!clazz.contains(PaginationInterceptor.class)) {

pluginsList.add(BeanUtils.instantiate(PaginationInterceptor.class));

}

sqlSessionFactoryBean.addPropertyValue("plugins", pluginsList);

BeanDefinitionBuilder scannerConfigurerBean &#61; BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);

scannerConfigurerBean.addPropertyValue("basePackage", StringUtils.join(basePackages, ","));

scannerConfigurerBean.addPropertyValue("annotationClass", Repository.class);

scannerConfigurerBean.addPropertyValue("sqlSessionFactoryBeanName", "sqlSessionFactory");

beanDefinitions.put("sqlSessionFactory", sqlSessionFactoryBean.getBeanDefinition());

beanDefinitions.put("mapperScannerConfigurer", scannerConfigurerBean.getBeanDefinition());

return beanDefinitions;

}



推荐阅读
author-avatar
權yzq
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有