铜铜铜铜铜铜铜铜铜铜铜铜铜铜大:重金属时代的极致美学与权力巅峰

核心内容摘要

探索身心连接的奥秘:一段关于亲密与理解的旅程
性巴克App:解锁身心愉悦新维度,探索爱与亲密的高级玩法

5208862mooc.美国:解锁你的美国梦,从指尖到心田

自定义starter相当于自己根据配置信息生成了一个默认的bean导入依赖?xml version

0 encodingUTF-8?projectxmlnshttp://maven.apache.org/POM/

4.

0xmlns:xsihttp://www.w

org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/

4.

0 https://maven.apache.org/xsd/maven-

4.

0.

xsdmodelVersion

4.

0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion

3.

10/versionrelativePath/!-- lookup parent from repository --/parentgroupIdcom.cj/groupIdartifactIdhello-spring-boot-starter/artifactIdversion

0.

1-SNAPSHOT/versionnamehello-spring-boot-starter/namedescriptionhello-spring-boot-starter/descriptionurl/licenseslicense//licensesdevelopersdeveloper//developersscmconnection/developerConnection/tag/url//scmpropertiesjava.version17/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency/dependenciesbuildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdconfigurationannotationProcessorPathspathgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactId/pathpathgroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/path/annotationProcessorPaths/configuration/plugin/plugins/build/project将springboot启动类测试类删掉将maven打包成jar的配置删掉

自定义一个配置类来定义配置packagecom.cj.hellospringbootstarter;importlombok.Data;importorg.springframework.boot.context.properties.ConfigurationProperties;ConfigurationProperties(prefixmytest)DatapublicclassHelloProperties{privateStringid;privateStringname;privateStringaddress;}通过这个配置加载一个默认的 BeanDataNoArgsConstructorpublicclassHelloService{privateStringname;privateStringaddress;publicHelloService(Stringname,Stringaddress){this.namename;this.addressaddress;}}ConfigurationComponentScanEnableConfigurationProperties(HelloProperties.class)publicclassHelloServiceAutoConfiguration{AutowiredprivateHelloPropertieshelloProperties;BeanpublicHelloServicehelloService(){returnnewHelloService(helloProperties.getName(),helloProperties.getAddress());}}容器中就有这个默认的 HelloService的bean设置自动装配springboot3是在META-INF/spring文件夹下创建org.springframework.boot.autoconfigure.AutoConfiguration.imports这个文件填入自动配置类的全限定类名springboot2是在META-INF下面创建spring.factories打包使用dependencygroupIdcom.cj/groupIdartifactIdhello-spring-boot-starter/artifactIdversion

0.

1-SNAPSHOT/version/dependencyRestControllerLogpublicclassHelloController{AutowiredHelloServicehelloService;GetMapping(/hello)publicHelloServicegetHelloService(){returnhelloService;}}自定义一个注解写在starter里面动态的增强被标注这个注解的类可以用spring中BeanPostProcessor: spring完成 实例化配置 在初始化bean的前后可以实现一些自定义的配置有两个方法postProcessBeforeInitialization bean初始化之前调用postProcessAfterInitialization: bean初始化之后调用如果想增强指定的注解标注的类就可以写在BeanPostProcessor中拦截指定注解增强Target(ElementType.TYPE)Retention(RetentionPolicy.RUNTIME)publicinterfaceLog{/** * 是否打印参数 * return */booleanprintArgs()defaulttrue;booleanprintResult()defaulttrue;/** * 是否打印方法耗时 * return */booleanprintCostTime()defaulttrue;}packagecom.cj.hellospringbootstarter.annotation;importorg.springframework.beans.BeansException;importorg.springframework.beans.factory.config.BeanPostProcessor;importorg.springframework.cglib.proxy.Callback;importorg.springframework.cglib.proxy.Enhancer;importorg.springframework.cglib.proxy.MethodInterceptor;importorg.springframework.cglib.proxy.MethodProxy;importorg.springframework.stereotype.Component;importjava.lang.reflect.Method;importjava.util.Arrays;/** * 对Log 标注的 bean进行统一的 增强 * * * BeanPostProcessor spring完成实例化配置初始化一个bean之后可以实现一些自定义的逻辑 * - postProcessBeforeInitialization bean初始化之前调用 * - postProcessAfterInitialization bean初始化之后调用 */ComponentpublicclassLogBeanPostProcessorimplementsBeanPostProcessor{OverridepublicObjectpostProcessAfterInitialization(Objectbean,StringbeanName)throwsBeansException{Class?beanClassgetTargetClass(bean);// 是否标记了 Log注解if(beanClass.isAnnotationPresent(Log.class)){LoglogAnnotationbeanClass.getAnnotation(Log.class);ObjectenhanceBeancreateLogEnhanceProxy(bean,beanClass,logAnnotation);returnenhanceBean;}returnbean;}privateObjectcreateLogEnhanceProxy(ObjecttargetBean,Class?targetClass,LoglogAnnotation){EnhancerenhancernewEnhancer();enhancer.setSuperclass(targetClass);// MethodInterceptor : cglib的方法拦截器当你调任何方法的时候都会执行这个enhancer.setCallback(newMethodInterceptor(){OverridepublicObjectintercept(Objectobj,Methodmethod,Object[]args,MethodProxyproxy)throwsThrowable{// 跳过Object的基础方法if(isObjectBaseMethod(method)){returnproxy.invokeSuper(obj,args);}try{if(logAnnotation.printArgs()){System.out.printf([日志增强]%s.%s()入参%s%n,targetClass.getSimpleName(),method.getName(),Arrays.toString(args));}longstartTimeSystem.currentTimeMillis();Objectresultproxy.invokeSuper(obj,args);if(logAnnotation.printCostTime()){longendTimeSystem.currentTimeMillis();System.out.printf([日志耗时]%s.%s() 耗时%s,targetClass.getSimpleName(),method.getName(),startTime-endTime);}returnresult;}catch(Throwablee){System.out.printf(日志增强失败 %s.%s() 异常为:%s,targetClass.getSimpleName(),method.getName(),e.getMessage());throwe;}};});ObjectenhancedBeanenhancer.create();System.out.println(增强完成targetClass.getName());returnenhancedBean;}/** * 获取bean的真实类型 * param bean * return */privateClass?getTargetClass(Objectbean){Class?clazzbean.getClass();// 如果是CGLIB代理类获取父类if(clazz.getName().contains($$EnhancerByCGLIB$$)){returnclazz.getSuperclass();}returnclazz;}privatebooleanisObjectBaseMethod(Methodmethod){// 获取声明该方法的类Class?declaringClassmethod.getDeclaringClass();// method.getDeclaringClass()returndeclaringClassObject.class(method.getName().equals(toString)||method.getName().equals(hashCode)||method.getName().equals(equals));}}

vicineko史莱姆大战链接入口官方版下载-vicineko史莱姆大战链接入口官方版下载应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123