Powered by Blogger.

Wednesday 15 June 2022

How to Develop Log4j for logging configuration and implementation in spring boot project/Application.

2 comments :
Introduction
Log4j is designed for both beginners and professionals. Our blogs post provides all the basic and advanced concepts of Log4j, such as Log4j for logging configuration and implementation etc. Log4j is a fast, reliable and flexible logging framework which is written in java. It is an open-source logging API for java. Simply the logging means some way to indicate the state of the system at runtime. Logs are used to capture and persists the important data and make it available for analysis at any point in time. Log4j2 is broken up in an API and an implementation (core), where the API provides the interface that applications should code to. Strictly speaking Log4j core is only needed at runtime and not at compile time. However, below we list Log4j as a compile time dependency to improve the startup time for custom plugins as it provides an annotation processor that generates a metadata file to cache plugin information as well as the necessary code to compile against to create custom plugins. . 
Using Log4j in your Apache Maven build To build with Apache Maven, add the dependencies listed below to your pom.xml file.


To keep your Log4j module versions in sync with each other, a pom.xml file is provided for your convenience. To use this with Maven, add the dependency listed below to your pom.xml file. When you specify the version identifier in this section, you don't have to specify the version in your section. pom.xml


Write a configuration of application.properties



As the file Path is given in the application.properties file, you have to create a folder named logs inside the project with the same name, you can also change its name. you will get to see all this in the video.

Go to The Live Example Video 

Thursday 2 June 2022

Run Multiple Microservices on single Port Using Zuul

1 comment :
Information
As you must have seen in these blogs links Multiple Microservices with Eureka Client Configuration that how we develop microservices and register those services on eureka server and we have seen how every service run on different port Number.
Introduction
Zuul is a JVM- based router and server-side load balance form Netflix.
Zuul's rule engine provides flexibility to write rules and filters to enhance routing in a spring cloud microservices architecture.
Routing it is an integral port of a microservice architecture.
How to Include Zuul Dependency
dependency: 
                groupid: org.springframework.cloud 
                 artifactid: spring-cloud-starter-netflix-zuul

Enbedded Zuul Reverse Proxy To enable it, annotate a spring boot man class with @EnableZuulProxy.
How to write Main Class Name is:A143mkGatewayApplication.java

Filter Class
Base abstract class for Zuulfilters. the base class defines abstract methods to define: filterType()- to classify a filter by type. standard type in Zuul are
  1. ErrorFilter
  2. PostFilter
  3. PreFilter
  4. RouteFilter

ErrorFilter.java

PostFilter.java

PreFilter.java

RouteFilter.java

application.properties
## client1-1 API URL 
zuul.routes.client-service-1.path=/cli-api/** 
zuul.routes.client-service-1.url=http://localhost:8081/ 
## client1-2 API URL 
zuul.routes.client-service-2.path=/cli2-api/** 
zuul.routes.client-service-2.url=http://localhost:8082/ 
ribbon.eureka.enabled=false 
server.port=8080

Create pom.xml

For step by step development working watch the video and learn yourself.





Monday 16 May 2022

Constructor and Constructor Chaining

No comments :
constructor
is the same as a method but the only difference is that the constructor has the same name as the class name. It is used to create an instance of the class. It is called automatically when we create an object of the class. It has no return type. Remember that a constructor cannot be abstract, final, synchronized, and static. We cannot override a constructor.
There are two types of constructor in Java:
  • Default Constructor (also known as a no-argument constructor) 
  • Parameterized Constructor

Constructor chaining: Constructor chaining is the process of calling one constructor from another constructor with respect to current object. 
Constructor chaining can be done in two ways:
  • Within same class: It can be done using this() keyword for constructors in same class 
  •  From base class: by using super() keyword to call constructor from the base class.



The Need of Constructor Chaining
Suppose, there are five tasks to perform. There are two ways to perform these tasks, either implement all the tasks in a single constructor or create separate tasks in a single constructor.
By using the constructor chaining mechanism, we can implement multiple tasks in a single constructor. So, whenever we face such types of problems, we should use constructor chaining. We can make the program more readable and understandable by using constructor chaining.

Watch YouTube video for live working example and develop yourself.



Wednesday 30 June 2021

A Rest API with Spring Boot using JSON, MySQL and JPA

2 comments :
Introduction:
In this article will look into how to create a REST API using HTTP methods for Create and Retrieve operations in Spring Boot along with MYSQL database. Spring Boot is an open source Java-based framework to build enterprise spring applications. . 
Overview: 
  • Create MYSQL database From WampServer.
  • Create the Spring Boot Project From STS-4.
  • Create Entity model class.
  • Create JPA Data Repository.
  • Create Service class.
  • Create Rest Controllers class.
  • Run the Project.
  • Testing using Postman.
  • Video Link for watching How to build API.

Create MYSQL database using WampServer.
Download WampServer install and Run-> go to phpMyAdmin and click.  
Open localhost/phpmyadmin/ 
Create Database Name is “hostel”.

Crate Table in hostel Database. Table Name is states with number of fields/Column.

Create Table column name, which is show in image.



Create the Spring Boot Project from STS-4:
It will write project name, group, artifact, version, description, package etc. 

 
Create Entity model class. 
  • Create the States model class to map with the States table.
  • @Entity is used to annotate that the class is an entity in the database.
  • @Table is used to annotate name of table in the database.
  • @id is used to reference that widget to your java file and access it from java file.
  • @GeneratedValue is used to generation strategies for the values of primary keys.
States.java

Create JPA Data Repository. 
  • Create StatsRepository Repository interface extending JPA Repository.
  • There are not need writing any SQL/MySql etc query.
  • @Repository annotation is used to indicate that the class provides the mechanism for storage, retrieval, search, and update and delete operation on objects.
StatsRepository.java

Create Service class. 
  • Create StateService service class to code the business logic and it acts as a middle layer between repository and controller class.
  • @Service annotation is a specialization of @Component annotation. Spring Service annotation can be applied only to classes. It is used to mark the class as a service provider.
  • @Transactional StateService annotate methods are executed in transactions.
    Example:
    @Transactional(readOnly = false, rollbackFor={Throwable.class, Exception.class}, propagation = Propagation.SUPPORTS)
  • @Autowired annotation is used for automatic dependency injection. Spring framework is built on dependency injection and we inject the class dependencies through spring bean configuration file.
StateService.java
Create Rest Controllers class. 
  • Create Rest StateController Controller class which contains all REST API endpoints for Create and Retrieve operations.
  • @RestController annotation was introduced in Spring 4.0 to simplify the creation of REST web services. It's a convenience annotation that combines @Controller and @ResponseBody– which eliminates the need to annotate every request handling method of the controller class with the @ResponseBody annotation.
StateService.java

Run the Project:
Write click to project and Run as->Spring boot App, it will check console to run project success and check running port.  



Testing using Postman.
Execute GET Request method to add a States to the Database. 

 

Video Link for watching How to build API.

Download Project: Download


Wednesday 10 February 2021

Spring Boot for Microservices

1 comment :
Spring Boot:
Spring Boot is an opinionated Java framework for building microservices based on the Spring dependency injection framework. Spring Boot allows developers to create microservices through reduced boilerplate, configuration, and developer friction. This is a similar approach to the two other frameworks we’ll look at. 
Spring Boot does this by: 
  • Favoring automatic, conventional configuration by default.
  • Curating sets of popular starter dependencies for easier consumption.
  • Simplifying application packaging.  
  • Baking in application insight (e.g., metrics and environment info)

Dependencies:
Spring was used in large enterprise applications that typically leveraged lots of different technology to do the heavy lifting: JDBC databases, message queues, file systems, application-level caching, etc. A developer would have to stop what she’s doing, switch cognitive contexts, figure out what dependencies belonged to which piece of functionality (“Oh, I need the JPA dependencies!”) and spend lots of time sorting out versioning mismatches or issues that would arise when trying to use these various pieces together. Spring Boot offers a large collection of curated sets of libraries for adding these pieces of functionality.  
These starter modules allow you to add things like: 
  • JPA persistence.
  • NoSQL databases like MongoDB, OracleDB, and Couchbase.
  • Redis caching.  
  • Tomcat/Jetty/Undertow servlet engine
  • JTA transactions.  

Adding a submodule to your application brings in the curated set of transitive dependencies and versions that are known to work together saving developers from having to sort out dependencies themselves.
The spring-tool-suite-4-4.2.0 can be installed a few different ways, including through package managers and by downloading Tools it straight from the website. Check for instructions on installing the STS most appropriate for your development environment. Once you’ve installed the STS tools, you should be able to check the version of Spring you have:
$ spring --version sts-4.2.0.RELEASE

Hello Example: Now that we have a Spring Boot application that can run, let’s add some simple functionality. We want to expose an HTTP/REST endpoint at /api/indexGet that will return “Hello Spring Boot from X” where X is the IP address where the service is running. To do this, navigate to src/main/java/com/a134mk/springboots. This location should have been created for you if you followed the preceding steps; remember, the groupId we passed to the spring init program did not apply groupId to the Java package hierarchy, and we’ve left it as it is which should be “com.a134mk”. Then create a new Java class called HolaRestController, as shown in code block. We’ll add a method named Hello() that returns a string along with the IP address of where the service is running. we’re going to make use of the following annotations in Example :
Let’s see what it takes to enable the actuator. Open up the pom.xml file for your Hello Spring Boot for microservice and add the following Maven dependency within
 the "<dependencies>...</dependencies>"  section:



@RestController 
 Tell Spring this is an HTTP controller capable of exposing HTTP endpoints (GET, PUT, POST, etc.). 
@RequestMapping 
 Map specific parts of the HTTP URI path to classes, methods, and parameters in the Java code. Note, import statements are omitted.


Go to Run->
OUTPUT:

Check Video for Similar Spring Boot Configuration:

Go Link...

Tuesday 2 February 2021

Online Snake Game

No comments :
Introduction
The game involves controlling a single block or snakehead by turning only left or right and up or down arrow key on keyboard by ninety degree until you manage to eat an fruets When you get the grout, the Snake grows an extra block or body segment.
Example: we are going to Step by Step Development of Online Snake Game with the Help of HTML, CSS and JavaScript.
Step 1. You have to create img folder and you can Download Number of images or background music file. Download Project Folder
Step 2. mKsnStyl.css
Step 3. mkSnkjavaScrip.js
Step 4. Snack.html

OUTPUT:

Download Game Project

Thursday 28 January 2021

Model–View–Controller (MVC) Design Patterns

No comments :
It is defined as follows
  • Models: Models are object used as blueprints for all of the objects that will be used in the application. 
  • Views: views are used to represent the presentational aspect of the information and data located in the models. 
  • Controller: controller are act as both of the models as well as views. They serve as a connection between the models and views.
Example: we are going to use MVC design Pattern to set and print the data of the collage Collages.
Step 1. Create Model.
Collage.java

Step 2. Create View.
CollageView.java

Step 3. Create Controller.
CollageController.java

Step 4. Use the CollageController methods to demonstrate MVC design pattern usage.
MVCPatternDemo.java

Step 5: Verify the output.
 Collage: 
 Name: ABCD 
 Roll No: 20 
 Collage: 
 Name: Manoj 
 Roll No: 20

Monday 4 January 2021

Design Patterns

No comments :
Introduction
Software Design Patterns can be defined as a software template or a description to solve a problem that occurs in multiple instances while designing a software application or a software framework. It is use to represent some of the best practices by experienced object oriented software developments.
Type of Design Patterns?
  1. Creational Design Patterns.
  2. Structural Design Patterns.
  3. Behavioral Design Patterns.
  4. JEE Design Patterns.
1> Creational Design Patterns:- Creational Design Patterns are concerned with the method of creating objects.
Type of Creational Design Patterns.
  1. Factory Design Patterns.
  2. Abstract factory Design Patterns.
  3. Singleton Design patterns.
  4. Prototype Design Patterns.
  5. Builder Design Patterns.
  6. Object pool Design Patterns.
2> Structural Design Patterns:- Structural Design Patterns deal with the composition of classes and objects which from larger structures.
Type of Structure Design Patterns.
  1. Façade Design Patterns.
  2. Bridge Design Patterns.
  3. Composite Design Patterns.
  4. Decorator Design Patterns.
  5. Adapter Design Patterns.
  6. Flyweight Design Patterns.
  7. Proxy Design Patterns.
  8. Filter Design Patterns.
3> Behavioral Design Patterns:- Behavioral Design Patterns are concerned with the responsibility and interaction between the objects.
Type of Behavioral Design Patterns.
  1. Strategy Design Patterns.
  2. Iterator Design Patterns.
  3. Mediator Design Patterns.
  4. Command Design Patterns.
  5. State Design Patterns.
  6. Observer Design Patterns.
  7. Template Design Patterns.
  8. Visitor Design Patterns.
4> JEE Design Patterns:- It is providing solutions to the JavaEE based Software Applications and frameworks.
Type of JEE Design Patterns.
  1. Transfer object Design Patterns.
  2. MVC Design Patterns.
  3. Dependency Injection Design Patterns.
  4. DAO (Data Access Object) Design Patterns.
  5. Business Design Patterns.
  6. Intercepting Filter Design Patterns.
  7. Service Object Patterns.

Factory Design Patterns

No comments :
Introduction
Factory Design Patterns follows the principal of “Define an interface or abstract class for creating an object but let the subclasses decide which class to instantiate”. The factory design Pattern is also known as virtual constructor.
Example:
We have three Milk Brand that describes the cost. Here we have three different Milk Brands namely, AMUL, SUDHA, AAVIN, along with their rate. Let us find milk brand of sale an each packet.

Public String MilkBrandCost(Stirng productame){
if(productame == null){  
             return null;  
            }  
If(productame.equals("AMUL")){
return "AMUL DARY and MRP:28";
}

If(productame.equals("SUDHA")){
return "SUDHA DARY and MRP:23";
}

If(productame.equals("AAVIN")){
return "AAVIN DARY and MRP:25";
}

}
....
return null;  


Sunday 17 December 2017

Multiple File convert to 7Zip File and attachments Through the Email !

No comments :
The Send Email Application has been created Using java with jdbc:oracle DataBase,with Multiple File convert to 7Zip File and attachments Through the Email .
Project  Folder and Jar File Position: 



Properties File: "dataBase.properties" is file Name
#Data Base Connection Name.
DATABASE_URL = jdbc:oracle:thin:@Host Name:Port Number:SID
DATABASE_USER = User Name
DATABASE_PASSWORD = Password
# Table Details information. 
TABLE_NAME = xyz
TABLE_FILE_NAME = xyz.FileColummn_Name
TABLE_TO_EMAIL = xyz.FileColummn_EmailId
# No Repaly email information. 
EMAIL_USER_NAME= xzy@gmail.com
EMAIL_USER_PASSWORD= xyzPassword
EMAIL_HOST = smtp.gmail.com
EMAIL_PORT = 587
EMAIL_SUBJECT= Write to Email Subjects
EMAIL_TEXTBODY= Write to Email Body
ATTACHED_FILE_URL= D://fileNameDR//
ATTACHED_FILE7ZIP_URL=D://7ZipTO_Mail//


Application Code:
1. Zip7AutoTOEmail.java

2. ZipCompress.java

3. SendMail.java