Friday, 13 September 2019

spring boot Creating Config Server

Creating Config Server

➤ point to git location
➤ pattern to search sub-directories
➤ point to alternate repose
➤ pattern to goto alternate repo
























Application.yml
---
server:
  port:
8888
spring:
  cloud:
    config:
      server:
        git:
          uri:
https://github.com/project/spring-cloudconfig-wa-tolls
         
search-paths:
           
- 'station*'

Main::

package dev.demo;



import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.config.server.EnableConfigServer;



@SpringBootApplication

@EnableConfigServer

public class SpringcloudM2ConfigserverGitApplication {



   public static void main(String[] args) {

      SpringApplication.run(SpringcloudM2ConfigserverGitApplication.class, args);

   }



}












Consuming Configuration




Application.properties
spring.application.name=s1rates

spring.profiles.active=default

spring.cloud.config.uri=http://localhost:8888

Controller
package demo.client;



import org.springframework.beans.factory.annotation.Value;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;



@Controller

public class RateController {

   @Value("${rate}")

   String rate;

   @Value("${laneCount}")

   String laneCount;

   @Value("${tollstart}")

   String tollstart;



   @RequestMapping("/rate")

   public String getRate(Model m){

      m.addAttribute("rateamount",rate);

      m.addAttribute("lanes",laneCount);

      m.addAttribute("tollstart",tollstart);

      //name of the view

      return "rateview";

   }



}


review.html


<!DOCTYPE HTML>

<html xmlns:th="http://www.thymeleaf.org">

<head>

    <title>Training: Config Client</title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <!-- Latest compiled and minified CSS -->

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"></link>

</head>

<body>

<div class="row">

    <div class="col-md-2"></div>

    <div class="col-md-8">

        <h1>Training: Spring Cloud Config Client</h1>

        <p th:text="'Your rate is: ' + ${rateamount} + ', number of lanes is ' + ${lanes} + ', toll start time is ' + ${tollstart} + ' and encrypted value is '+ ${connstring} +'!'" />

    </div>

    <div class="col-md-2"></div>

</div>

</body>

</html>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.