Spring Cloud integrates spring Boot Admin

Source: Internet
Author: User

Introducing POM Dependencies:

    <dependencies> <dependency> <groupId>de.codecentric</groupId> &lt            ;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&lt ;/groupid> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </depen Dency> <!--end::d ependency-eureka[]-<dependency> &LT;GROUPID&GT;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> &lt ;groupid>org.springframework.boot</groupid> &LT;ARTIFACTID&GT;SPRING-BOOT-MAVEN-PLUGIN&LT;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.