当前位置 主页 > 服务器问题 > Linux/apache问题 > 最大化 缩小
5:编写注解实现类: EnableUserInfoTransmitterAutoConfiguration
package spring.cloud.common.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import spring.cloud.common.interceptor.TransmitUserInfoFeighClientInterceptor; import spring.cloud.common.filter.TransmitUserInfoFilter; //@Configuration 在业务端通过注解EanbleUserInfoTransmitter加载 public class EnableUserInfoTransmitterAutoConfiguration { public EnableUserInfoTransmitterAutoConfiguration() { } @Bean public TransmitUserInfoFeighClientInterceptor transmitUserInfo2FeighHttpHeader(){ System.out.println("-----TransmitUserInfoFeighClientInterceptor"); return new TransmitUserInfoFeighClientInterceptor(); } @Bean public TransmitUserInfoFilter transmitUserInfoFromHttpHeader(){ System.out.println("-----TransmitUserInfoFilter"); return new TransmitUserInfoFilter(); } }
6:编写注解 EnableUserInfoTransmitter
package com.test.domi.annotation; import com.test.domi.config.EnableUserInfoTransmitterAutoConfiguration; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @Documented @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Import({EnableUserInfoTransmitterAutoConfiguration.class}) public @interface EnableUserInfoTransmitter { }
7:在启动类上标记注解即可使用(无侵入)
package com.test.domi; import com.test.domi.annotation.EnableUserInfoTransmitter; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @EnableDiscoveryClient @SpringBootApplication @MapperScan("com.test.domi.dao") @EnableUserInfoTransmitter public class TestCommonClient { public static void main(String[] args){ SpringApplication.run(TestCommonClient.class,args); } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持IIS7站长之家。