Introducing POM Dependencies:
<dependencies> <dependency> <groupId>de.codecentric</groupId> < ;artifactid>spring-boot-admin-starter-server</artifactid> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot-starter-web</ artifactid> </dependency> <dependency> <groupId>org.springframework.boot< /groupid> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!--tag::d ependency-eureka[]--<dependency> <groupid>org.springframework.cloud< ;/groupid> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </depen Dency> <!--end::d ependency-eureka[]-<dependency> <GROUPID>ORG.JOLOKIA&L T;/groupid> <artifactId>jolokia-core</artifactId> </dependency> <dependency> <gr Oupid>org.springframework.boot</groupid> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> &L t;finalname>${project.artifactid}</finalname> <plugins> <plugin> < ;groupid>org.springframework.boot</groupid> <ARTIFACTID>SPRING-BOOT-MAVEN-PLUGIN</ARTIFAC tid> <executions> <execution> <goals> <goal>repackage</goal> <goal>build-info</goal> </goals> </execution> </executions> <configuration> <mainClass>de.codecentric.boot.admin.SpringBootAdminApplication</mainClass> <addResources>false</addResources> </configuration> </plugin> </plugins> </bui Ld>
Startup class:
@EnableDiscoveryClient @enableadminserver@springbootapplication Public class springbootadminapplication { publicstaticvoid main (string[] args) { Springapplication.run (springbootadminapplication. class , args);} }
Security configuration:
/** * @author Rancheng * @date 2018/9/7 11:41*/@Configuration @enableautoconfiguration Public classsecurityconfig {@Profile ("insecure") @Configuration Public Static classSecuritypermitallconfig extends Websecurityconfigureradapter {Privatefinal String Admincontextpath; Publicsecuritypermitallconfig (adminserverproperties adminserverproperties) { This. Admincontextpath =Adminserverproperties.getcontextpath (); } @Overrideprotected voidConfigure (Httpsecurity http) throws Exception {http.authorizerequests (). Anyrequest () . Permitall (). and (). CSRF (). Csrftokenreposito Ry (Cookiecsrftokenrepository.withhttponlyfalse ()). Ignoringantmatchers (Admincontextpath+"/instances", Admincontextpath +"/actuator/**"); }} @Profile ("Secure") @Configuration Public Static classSecuritysecureconfig extends Websecurityconfigureradapter {Privatefinal String Admincontextpath; Publicsecuritysecureconfig (adminserverproperties adminserverproperties) { This. Admincontextpath =Adminserverproperties.getcontextpath (); } @Overrideprotected voidConfigure (Httpsecurity http) throws Exception {//@formatter: OffSavedrequestawareauthenticationsuccesshandler Successhandler =NewSavedrequestawareauthenticationsuccesshandler (); Successhandler.settargeturlparameter ("Redirectto"); Successhandler.setdefaulttargeturl (Admincontextpath+"/"); Http.authorizerequests (). Antmatchers (Admincontextpath+"/assets/**"). Permitall (). Antmatchers (Admincontextpath+"/login"). Permitall (). Anyrequest (). authenticated (). and (). Formlogin (). LoginPage (Admincontextpath+"/login"). Successhandler (Successhandler). and (). Logout (). Logouturl (Admincontextpath+"/logout"). and (). Httpbasic (). and (). CSRF (). Csrftokenrepository (Cooki Ecsrftokenrepository.withhttponlyfalse ()). Ignoringantmatchers (Admincontextpath+"/instances", Admincontextpath +"/actuator/**"); } }}
Login page:
After logging in:
Spring Cloud integrates spring Boot Admin