Recent PostsMonitoring Spring boot application using Prometheus and GrafanaJuly 5, 2020UncategorizedIn continuation with previous article ,we will see how we can monitor spring boot application developed in earlier post with actuator. We have already seen prometheus tool for monitoring application but as prometheus doesn’t provide better visualization experience, we have to go with other tools which has rich UI for better visualization of application metrics. You can use Grafana for the better visualization . Grafana While Prometheus does provide some crude visualization, Grafana offers a rich UI where you can build up custom graphs quickly and create a dashboard out of many graphs in no time. You can also import many community built dashboards for free and get going. Grafana can pull data from various data sources like Prometheus, Elasticsearch, InfluxDB, etc. It also allows you to set rule-based alerts, which then can notify you over Slack, Email, Hipchat, and similar. Let’s start with running Grafana using Doc You can download grafana for windows using below link – https://grafana.com/grafana/dashboards If you visit http://localhost:3000, you will be redirected to a login page: Login page Default credentials to login are admin/admin . Since Grafana works with many data sources, we need to define which one we’re relying on. In our case we have to select Prometheus as our data source: Datasource configuration Select Prometheus from below provided options – Now, add the URL that Prometheus is running on, in our case http://localhost:9090 and select Access to be through a browser. At this point, we can save and test to see if the data source is working correctly: You can search for JVM (Micrometer) dashboard on grafana website and provide its ID in next step to import that dashboard into grafana – You can find the dashboard ID as highlighted in below screenshot – As i mentioned earlier, Grafana has lots of of pre-built dashboards. For Spring Boot projects, the JVM dashboard is popular. We are going to use JVM micrometer (ID = 4701) dashboard in this example . Click on highlighted plus icon and then import – Select the Prometheus datasource name created in earlier steps as highlighted in below screenshot- Once you click on import , your dashboard is ready . You can have a look at all the metrics exposed by prometheus on a single dashboard – I hope this tutorial is helpful for you to configure your spring boot application with Grafana In this article, we used Micrometer to reformat the metrics data provided by Spring Boot Actuator and expose it in a new endpoint. This data was then regularly pulled and stored by Prometheus, which is a time-series database. Ultimately, we’ve used Grafana to visualize this information with a user-friendly dashboard. Monitoring an application’s health and metrics helps us manage it better, notice unoptimized behavior, and better understand its performance. This especially holds true when we’re developing a system with many microservices, where monitoring each service can prove to be crucial when it comes to maintaining our system. Based on this information, we can draw conclusions and decide which microservice needs to scale if further performance improvements can’t be achieved with the current setup. Github Downlod Link: Download... Read more...Spring mvc integration with prometheus ExampleApril 27, 2020Spring CoreIn this article ,we will see how we can monitor spring MVC applications using prometheus tool . You wont get much documentation for this setup on web. Prometheus is mostly configured with spring boot easily. But in order to configure it with spring MVC based application , it requires some additional configurations – Prometheus Prometheus is a time-series monitoring application written in Go. It can run on a server, in a docker container, or as part of a Kubernetes cluster (or something similar). Prometheus collects, stores, and visualizes time-series data so that you can monitor your systems. You can tell Prometheus exactly where to find metrics by configuring a list of “scrape jobs”. Applications that are being monitored can provide metrics endpoints to Prometheus using any one of the many client libraries available; additionally, separate exporters can gather metrics from applications to make them available in Prometheus. Metrics get stored locally for 15 days, by default, and any Prometheus server can scrape another one for data. Additionally, remote storage is another option for Prometheus data – provided there is a reliable remote storage endpoint. Benefits: The option of “service discovery” allows Prometheus to keep track of all current endpoints effortlessly. Outages are quickly detected .The PromQL query language is incredibly flexible and Turing-complete. There’s also a very low load on the services monitored (metrics get stored in memory as they get generated), allowing fewer resources to get used. Additionally, Prometheus users can control traffic volumes, access metrics in the browser, and allow for easy reconfiguration. Step 1 : Spring MVC application pom.xml configuration Below prometheus dependencies are required in pom.xml for project – 0.6.0 io.prometheus simpleclient ${prometheus.version} io.prometheus simpleclient_hotspot ${prometheus.version} io.prometheus simpleclient_servlet ${prometheus.version} io.prometheus simpleclient_pushgateway ${prometheus.version} io.prometheus simpleclient_spring_web ${prometheus.version} com.fasterxml.jackson.core jackson-core 2.5.2 Step 2 : Spring MVC application web.xml configuration We need configure MetricsServlet to capture the metrics of our spring mvc application as below – PrometheusServlet io.prometheus.client.exporter.MetricsServlet PrometheusServlet /metrics Step 3: Add an interceptor class This will intercept all the requests coming to application and capture the metrics to be exposed to prometheus – package com.myjavablog.config; import io.prometheus.client.Counter; import io.prometheus.client.Gauge; import io.prometheus.client.Histogram; import io.prometheus.client.Summary; import org.apache.log4j.Logger; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author anupb */ public class PrometheusMetricsInterceptor extends HandlerInterceptorAdapter { private static Logger logger = Logger.getLogger(PrometheusMetricsInterceptor.class); private static final Histogram requestLatency = Histogram.build() .name(“service_requests_latency_seconds”) .help(“Request latency in seconds.”) .labelNames(“systemId”, “appId”, “type”, “name”, “method”).register(); private ThreadLocal timerThreadLocal; @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return super.preHandle(request, response, handler); } @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { String name = this.getName(request, handler).toLowerCase(); String method = request.getMethod().toUpperCase(); timerThreadLocal = new ThreadLocal(); timerThreadLocal.set(requestLatency.labels(name, method).startTimer()); super.postHandle(request, response, handler, modelAndView); } @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { super.afterCompletion(request, response, handler, ex); if (timerThreadLocal.get() != null) { timerThreadLocal.get().observeDuration(); } } @Override public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { super.afterConcurrentHandlingStarted(request, response, handler); } private String getName(HttpServletRequest request, Object handler) { String name = “”; try { if (handler != null && handler instanceof HandlerMethod) { HandlerMethod method = (HandlerMethod) handler; String className = ((HandlerMethod) handler).getBeanType().getName(); name = className + “.” + method.getMethod().getName(); } else { name = request.getRequestURI(); } } catch (Exception ex) { logger.error(“getName”, ex); } finally { return name; } } } Step 4: Add prometheus initialization configuration This will expose the metrics to prometheus server – package com.myjavablog.config; public class PrometheusConfig { private static Logger logger = Logger.getLogger(PrometheusConfig.class); @PostConstruct public void initialize() { logger.info(“prometheus init…”); DefaultExports.initialize(); logger.info(“prometheus has been initialized…”); } } Step 5: Add an interceptor to spring-mvc.xml You need to first add the schema location as below – http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Then you need to add below tag – <mvc:interceptors> <bean class="com.xx.config.PrometheusMetricsInterceptor"/> </mvc:interceptors> Step 6: Add configuration to applicationcontext.xml Once all this configuration is done , you can add the application URL in prometheus. These parameters are useful to monitor your spring MVC application.... Read more...Monitoring Spring boot applications using actuator and prometheusMarch 15, 2020Spring BootIn this article ,we will see how we can monitor spring boot applications using actuator spring boot project and prometheus tool . Prometheus Prometheus is a time-series monitoring application written in Go. It can run on a server, in a docker container, or as part of a Kubernetes cluster (or something similar). Prometheus collects, stores, and visualizes time-series data so that you can monitor your systems. You can tell Prometheus exactly where to find metrics by configuring a list of “scrape jobs”. Applications that are being monitored can provide metrics endpoints to Prometheus using any one of the many client libraries available; additionally, separate exporters can gather metrics from applications to make them available in Prometheus. Metrics get stored locally for 15 days, by default, and any Prometheus server can scrape another one for data. Additionally, remote storage is another option for Prometheus data – provided there is a reliable remote storage endpoint. Benefits: The option of “service discovery” allows Prometheus to keep track of all current endpoints effortlessly. Outages are quickly detected .The PromQL query language is incredibly flexible and Turing-complete. There’s also a very low load on the services monitored (metrics get stored in memory as they get generated), allowing fewer resources to get used. Additionally, Prometheus users can control traffic volumes, access metrics in the browser, and allow for easy reconfiguration. Part 1: Spring boot application configuration We will create a simple spring boot REST application which will expose the metrics to prometheus. Please find below project structure of application – Project Structure Below is the pom.xml required for project – 4.0.0 com.db spring-boot-prometheus 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.1.9.RELEASE 1.8 org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-web io.micrometer micrometer-registry-prometheus org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin We need spring-boot-starter-actuator dependency ,this would expose the endpoints of our application and makes it available to prometheus server. You can run the application and check the endpoints exposed by actuator by hitting below link in browser – http://localhost:8081/actuator Micrometer micrometer-registry-prometheus dependency is required to register metrics with prometheus server. It exposes Actuator metrics to external monitoring systems such as Prometheus, Netflix Atlas, AWS Cloudwatch, and many more. Similarly, Micrometer automatically exposes /actuator/metrics data into something your monitoring system can understand. All you need to do is include that vendor-specific micrometer dependency in your application. Micrometer is a separate open-sourced project and is not in the Spring ecosystem, so we have to explicitly add it as a dependency. Since we will be using Prometheus, let’s add it’s specific dependency in our pom.xml: Part 2: Prometheus Server Configuration For this example , i will be installing portable prometheus on local system . You can download the prometheus setup from official prometheus website as below – https://prometheus.io/download/ You need to make below changes in prometheus.yml file of prometheus configuration to scrape the metrices your application .Please add below job to scrape the metrices of your application – # Details to connect Prometheus with Spring Boot actuator end point to scrap the data # The job name is added as a label `job=` to any time series scraped from this config. – job_name: ‘spring-actuator’ # Actuator end point to collect the data. metrics_path: ‘/actuator/prometheus’ #How frequently to scape the data from the end point scrape_interval: 5s #target end point. We are using the Docker, so local host will not work. You can change it with #localhost if not using the Docker. static_configs: – targets: Run the prometheus server by double clicking prometheus.exe flie . Now prometheus console will open and it will strat gathering the metrices of your application. You can access the prometheus server in browser using http://localhost:9090 Targets for metrics Classes loaded in JVM prometheus metrics Number of Threads in different states You can gather the metrices of your application by selecting the various parameters provided by prometheus like – jvm_classes_loaded_classesjvm_threads_live_threadsjvm_threads_states_threadsjvm_threads_states_threadstomcat_global_request_seconds_count These parameters are useful to monitor your systems. In the next article, we will create a prometheus server using docker and expose the metrices. Github Downlod Link: Download... Read more...Spring Cloud Eureka and Hystrix Circuit Breaker using MicroservicesJanuary 10, 2020MicroserviceIn this tutorial, we will use a microservice application created in previous post ( Microservices Example using Spring Cloud Eureka ) and add circuit breaker pattern using Hystrix Spring library in java. Using Hystrix in your application helps to add defensive mechanism and makes applications more resilient and fault tolerant. Tools Required – Java 8IntelliJ IDE We have created three different applications as below – Eureka Service– This Service will register every microservice and then the client microservice will look up the Eureka server to get a dependent microservice to get the job done.This Eureka Server is owned by Netflix and in this, Spring Cloud offers a declarative way to register and invoke services by using Java annotation.demo-server – This service will return a simple hello message.demo-client – It is similar to the standalone client service created in Bootiful Development with Spring Boot. It will consume the APIs provided by demo-server through Eureka Service . Hystrix Documentation – https://github.com/Netflix/Hystrix/wiki Microservices are deployed on Cloud . As cloud provides a distributed environment , there are more chances that some of your services may be down at some point of time. You can have several micro-services in your application which are dependent on each other. So one service can call to other service. If destination service is down then source will get an exception in normal scenario. But with the help of Hystrix annotations , you can add fallback mechanism and handle the exception in services. Thus it makes your service more fault tolerant, resilient . You need to add below dependency in your demo-client service application to enable Hystrix circuit breaker pattern – <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> <version>1.2.5.RELEASE</version> </dependency> We just have to add few annotations to handle fallback or break the service call in case your destination service(demo-server) is down. We need to change main class to enable Hystrix circuit breaker – package com.myjavablog.democlient; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @EnableCircuitBreaker @EnableDiscoveryClient @SpringBootApplication public class DemoClientApplication { public static void main(String[] args) { SpringApplication.run(DemoClientApplication.class, args); } } @Configuration class Config{ @Bean @LoadBalanced public RestTemplate restTemplate(){ return new RestTemplate(); } } Also we need to change controller class to add fallback mehod as below – package com.myjavablog.democlient; import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @RestController @RequestMapping("/demo/hello/client") public class TestController { @Autowired public RestTemplate restTemplate; @GetMapping @HystrixCommand(fallbackMethod = "handleFallback") public String test(){ String url = "http://demo-server/demo/hello/server"; return restTemplate.getForObject(url, String.class); } public String handleFallback(){ return "Fallback hello service"; } } By default hystrix has timeout of 1 second for every request. So we need to disable timeout by setting below property in application.properties file – hystrix.command.default.execution.timeout.enabled=false So now i am intentionally stopping demo-server microservice and then we will make call to api to see fallback is working properly .You can see demo-server is not registered with Eureka below – So now when you call the service ,it should show you a fallback message as below – Github Downlod Link: Download... Read more...Benefits of microservicesJanuary 1, 2020MicroserviceYou start building microservices because they give you a high degree of flexibility and autonomy with your development teams, but you and your team quickly find that the small, independent nature of microservices makes them easily deployable to the cloud. Once the services are in the cloud, their small size makes it easy to start up large numbers of instances of the same service, and suddenly your applications become more scalable and with forethought, more resilient. A microservice architecture has the following characteristics: Application logic is broken down into small-grained components with well defined boundaries of responsibility that coordinate to deliver a solution.Each component has a small domain of responsibility and is deployed completely independently of one another. Microservices should have responsibility for a single part of a business domain. Also, a microservice should be reusable across multiple applications.Microservices communicate based on a few basic principles (notice I said principles, not standards) and employ lightweight communication protocols such as HTTP and JSON (JavaScript Object Notation) for exchanging data between the service consumer and service provider.The underlying technical implementation of the service is irrelevant because the applications always communicate with a technology-neutral protocol (JSON is the most common). This means an application built using a microservice application could be built with multiple languages and technologies.Microservices—by their small, independent, and distributed nature—allow organizations to have small development teams with well-defined areas of responsibility. These teams might work toward a single goal such as delivering an application, but each team is responsible only for the services on which they’re working.... Read more...What’s a microservice?December 29, 2019MicroserviceBefore the concept of microservices evolved, most web-based applications were built using a monolithic architectural style. In a monolithic rchitecture, an application is delivered as a single deployable software artifact. All the UI (user interface), business and database access logic are packaged together into a single application artifact and deployed to an application server.While an application might be a deployed as a single unit of work, most of the time there will be multiple development teams working on the application. Each development team will have their own discrete pieces of the application they’re responsible for and oftentimes specific customers they’re serving with their functional piece. For example, customer relations management (CRM) application that involves the coordination of multiple teams including the UI, the customer master, the data warehouse and the mutual funds teams. Below Figure illustrates the basic architecture of this application. Monolithic applications force multiple development teams to artificially synchronize their delivery because their code needs to be built, tested, and deployed as an entire unit. The problem here is that as the size and complexity of the monolithic CRM application grew, the communication and coordination costs of the individual teams working on the application didn’t scale. Every time an individual team needed to make a change, the entire application had to be rebuilt, retested and redeployed. A microservice is a small, loosely coupled, distributed service. Microservices allow you to take a large application and decompose it into easy-to manage components with narrowly defined responsibilities. Microservices help combat the traditional problems of complexity in a large code base by decomposing the large code base down into small, well-defined pieces. The key concept you need to embrace as you think about microservices is decomposing and unbundling the functionality of your applications so they’re completely independent of one another. If we take the CRM application we saw in above figure and decompose it into microservices, it might look like what’s shown in below figure.Looking at below figure, you can see that each functional team completely owns their service code and service infrastructure. They can build, deploy, and test independently of each other because their code, source control repository, and the infrastructure (app server and database) are now completely independent of the other parts of the application. A microservice architecture of CRM application would be decomposed into a set of microservices completely independent of each other, allowing each development team to move at their own pace.... Read more...Microservices Example using Spring Cloud EurekaDecember 29, 2019MicroserviceIn this tutorial, we will create a demo microservice using spring boot framework in java. Tools Required – Java 8IntelliJ IDE We need to create three different applications as below – Eureka Service– This Service will register every microservice and then the client microservice will look up the Eureka server to get a dependent microservice to get the job done.This Eureka Server is owned by Netflix and in this, Spring Cloud offers a declarative way to register and invoke services by using Java annotation.demo-server – This service will return a simple hello message.demo-client – It is similar to the standalone client service created in Bootiful Development with Spring Boot. It will consume the APIs provided by demo-server through Eureka Service . 1. Eureka Service We need to create new project in intelliJ editor by selecting below dependencies – Project Setup Maven dependencies You need to do below configurations to create Eureka service which allows other microservices to register with it . package com.myjavablog; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class EurekaServiceApplication { public static void main(String[] args) { SpringApplication.run(EurekaServiceApplication.class, args); } } You need to create application.yml to configure your EurekaService project as register service. Other services will be able to register themselves with EurekaService. So you need to do below configurations – eureka: client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0 Now you can run the application . Once the application is up and running you can go to below URL and see EurekaService is working . You will be able to see below home page of eureka- As no instances are registered with EurekaService , you can see No instances available message as highlighted above . Now we will create services which will register with our Eureka Server. 2. Demo Server This is a simple REST based webservice. This will be registering itself with the EurekaService. This service has a simple API which is just returning hello message. Create a project structure as shown below in IntelliJ IDE – Setup Maven Dependencies required Project structure is as shown below – You need to include Eureka Discovery client dependency in your pom file. Once the application is up and running , you can see instance of demo-server registered on EurekaService as shown below – 3. Demo Client Same way as Demo server , we need to create demo client which will consume services provided by demo-server through EurekaService. demo-client will have autowired RestTemplate to call the services provided by demo-server. package com.myjavablog.democlient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; @RestController @RequestMapping("/demo/hello/client") public class TestController { @Autowired public RestTemplate restTemplate; @GetMapping public String test(){ String url = "http://demo-server/demo/hello/server"; return restTemplate.getForObject(url, String.class); } } Also you can see in the above code , we are using String url = “http://demo-server/demo/hello/server” demo-server is the name specified in the application.yml file of demo-server project . So instead of using http://localhost:8071/demo/hello/server we are using http://demo-server/demo/hello/server . demo-server is the name registered on Eureka server for demo-server application as shown below – spring: application: name: demo-server server: port: 8071 eureka: client: registerWithEureka: true fetchRegistry: true serviceUrl: defaultZone: http://localhost:8070/eureka/ instance: hostname: localhost Once the application is up and running , you can see the demo-client is registered on Eureka Server as below – When you call the APIs from demo client ,it will internally call demo-server APIs through Eureka Service . Eureka server handles all routing and load balancing part. So even if you scale up your services in future by creating multiple instances, you can go on and use the services with the name which is registered on Eureka server. Github Downlod Link: Download... Read more...Spring Boot profilesDecember 1, 2019Spring BootIn this article, we will see profiles for spring boot project – Github Link – Download What are Profiles? Every enterprise application has many environments, like: Dev | Test | Stage | Prod | UAT / Pre-Prod Each environment requires a setting that is specific to them. For example, in DEV, we do not need to constantly check database consistency. Whereas in TEST and STAGE, we need to. These environments host specific configurations called Profiles. How do we Maintain Profiles? In spring boot application, we need different configurations for different environments. We have application.properties file to maintain application specific properties. In order to create profiles for different environments , we need to create various properties files as below – DEV – application-dev.properties TEST– application-test.properties PROD – application-prod.properties Step 1: Create below project structure in IntelliJ Step 2: We are creating 3 different property files for below mentioned environments – DEV – application-dev.properties TEST– application-test.properties PROD – application-prod.properties Of course, the application.properties will remain as a master properties file, but if we override any key in the profile-specific file, the latter will gain precedence. Step 3: Specify in application.properties file which environment property needs to be loaded spring.profiles.active=prod spring.application.name=springbootprofiles app.message = This is Application property for ${spring.application.name} Here we are loading PROD properties when application gets booted. Step 4: Define DB configuration properties for in respective properties file and add code in DBConfiguration.class to pick the appropriate settings. package com.myjavablog.config; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @Configuration @ConfigurationProperties("spring.datasource") public class DBConfiguration { private String driverClassName; private String url; private String username; private String password; public String getDriverClassName() { return driverClassName; } public void setDriverClassName(String driverClassName) { this.driverClassName = driverClassName; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Profile("dev") @Bean public String devDatabaseConnection() { System.out.println("DB connection for DEV - H2"); System.out.println(driverClassName); System.out.println(url); return "DB connection for DEV - H2"; } @Profile("test") @Bean public String testDatabaseConnection() { System.out.println("DB Connection to TEST -H2"); System.out.println(driverClassName); System.out.println(url); return "DB Connection to TEST -H2"; } @Profile("prod") @Bean public String prodDatabaseConnection() { System.out.println("DB Connection to PROD - H2"); System.out.println(driverClassName); System.out.println(url); return "DB Connection to PROD - H2"; } } This will load the properties file as per the spring.profiles.active property we have mentioned in application.properties file. Step 5: Output As per the application boot time logs below, you can see PROD database is loaded during application boot up. 2019-12-01 23:29:07.199 INFO 5728 --- rmationExtractorJdbcDatabaseMetaDataImpl : HHH000262: Table not found: user_details 2019-12-01 23:29:07.419 INFO 5728 --- j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' DB Connection to PROD - H2 org.h2.Driver jdbc:h2:mem:proddb;DB_CLOSE_ON_EXIT=FALSE 2019-12-01 23:29:09.147 INFO 5728 --- s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot[email protected]e25951c: startup date ; root of context hierarchy You can connect to database as shown below –... Read more...How to create a Chat Bot in AzureOctober 24, 2019Azure / CloudClick Create new resource link found on the upper left-hand corner of the Azure portal, then select AI + Machine Learning > Web App bot. Once you select “Web App bot” , you have to configure it with below fields – Once you click on Create , your bot will be created .In the Bot Management section, click Test in Web Chat. Azure Bot Service will load the Web Chat control and connect to your bot. You can download the bot source code as shown below and configure the bot as per your requirements .... Read more...How to Deploy a Spring Boot application to AzureOctober 22, 2019Azure / CloudBelow are the tools required for this tutorial – MavenGit ClientAzure CLIJDKAzure Subscription Create a Spring boot application Open a git bash terminal window.Clone the below sample project into the directory you created by typing git clone https://github.com/AnupBhagwat7/azure-demo-service.gitChange to the directory of the completed project by typing cd azure-demo-service Build the JAR file using Maven by typing mvn clean packageWhen the web app has been created, start it by typing mvn spring-boot:runTest it locally by visiting http://localhost:8080/api/helloYou should see the following message displayed: Hello spring boot on azure! REST API Response in Browser Create an Azure service principal In this section, you will create an Azure service principal that the Maven plugin uses when deploying your web app to Azure. Open a terminal window.Sign into your Azure account with the Azure CLI by typing az loginCreate an Azure service principal by typing az ad sp create-for-rbac –name “uuuuuuuu” –password “pppppppp” (uuuuuuuu is the user name and pppppppp is the password for the service principal). Azure should print out a JSON response resembling this: { "appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", "displayName": "servicename", "name": "http://servicename", "password": "pass", "tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt" } Configure Maven to use your Azure service principal In this section, you will configure Maven to authenticate using your Azure service principal for web app deployment. Open your Maven settings.xml file in a text editor (usually found at either /etc/maven/settings.xml or $HOME/.m2/settings.xml). Add your Azure service principal settings from the previous section of this tutorial to the collection in the settings.xml file as shown below: <servers> <server> <id>azure-auth</id> <configuration> <client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client> <tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant> <key>pass</key> <environment>AZURE</environment> </configuration> </server> </servers> Save and close the settings.xml file. You need to configure Maven Plugin for Azure Web Apps deployment. Below entry needs to be added in pom.xml – <plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId> <version>1.1.0</version> <configuration> <!-- Azure configuration --> </configuration> </plugin> Build and deploy your app to Azure Once you have configured all of the settings in the previous sections, you are ready to deploy your web app to Azure. From the git bash terminal window, deploy your web app to Azure with Maven by typing mvn azure-webapp:deploy Maven will deploy your web app to Azure using a plugin already in the build file of the sample project you cloned earlier. If the web app doesn’t already exist, it will be created. When your web app has been deployed, visit the Azure portal to manage it. It will be listed in App Services as show below: Web app will be listed in Azure portal App Services. Click on the application. From there, the publicly-facing URL for your web app will be listed in the Overview section. Determining the URL for your web app You can click on this link to visit the Spring Boot application and interact with it.... Read more...