Wikipedia

Search results

Wednesday, March 13, 2019

Spring framework architecture

Spring framework Architecture

Image result for Spring Framework

Image result for Spring Framework

Spring Framework Architecture

Image result for Spring Framework

Spring Boot Developer Toolsand Live Reload

When we develop web applications with Java, we had to restart the server to pick upall changes. This kills productivity. Spring Boot Developers Tools provides solutions toautomatically pick up changes without a complete server restart. Lets get productivewith Spring Boot Developer Tools


Add this dependency to your Spring Boot Project pom.xml

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
  • Restart the application.
  • You are all Set.
  • Go ahead and make a simple change to your controller. You would see that these
  • changes are automatically picked up.

What kind of changes does Spring Boot DeveloperTools pick up?
By default, any entry on the classpath that points to a folder will be monitored for changes.
Here are few important things to note:
These folders will not trigger reload by default
/META-INF/maven
/META-INF/resources
/resources
/static
/public
/templates
You can configure additional folders to scan.
application.properties
spring.devtools.restart.additional-paths = /path-to-folder
You can also configure folders to exclude.

spring.devtools.restart.exclude=static/**,public/**
.

s



You can also configure folders to exclude.
spring.devtools.restart.exclude=static/**,public/**



Auto refresh your browser with LiveReload
Spring Boot Developer Tools auto loads the changes to application. But if you are
developing a web application, you would need to refresh the browser to pickup the
change.
LiveReload aims to solve this problem
LiveReload offers extensions for browsers
Download from
http://livereload.com/extensions/
Once you install the LiveReload plugin for your browser, you would see that the page
auto refreshes when you make a change in application code.

What is the core problem that Spring Framework solves

what is Spring Framework
  • Most important feature of Spring Framework is Dependency Injection
  • build decoupled systems enterprise application
It’s packed with some nice features like Dependency Injection and out of the box modules like:
  • Spring JDBC
  • Spring MVC
  • Spring Security
  • Spring AOP
  • Spring ORM
  • Spring Test
These modules can drastically reduce the development time of an application.
For example, in the early days of Java web development, we needed to write a lot of boilerplate code to insert a record into a data source. But by using the JDBCTemplate of the Spring JDBC module we can reduce it to a few lines of code with only a few configurations.

What is Spring Boot?

Spring Boot is basically an extension of the Spring framework which eliminated the boilerplate configurations required for setting up a Spring application.
It takes an opinionated view of the Spring platform which paved the way for a faster and more efficient development eco-system.
Here are just a few of the features in Spring Boot:
  • Opinionated ‘starter’ dependencies to simplify build and application configuration
  • Embedded server to avoid complexity in application deployment
  • Metrics, Helth check, and externalized configuration
  • Automatic config for Spring functionality – whenever possible

Spring Boot provides a number of starter dependencies for different Spring modules. Some of the most commonly used ones are:
  • spring-boot-starter-data-jpa
  • spring-boot-starter-security
  • spring-boot-starter-test
  • spring-boot-starter-web
  • spring-boot-starter-thymeleaf
we can say that the Spring Boot is simply an extension of Spring itself to make the development, testing, and deployment more convenient.

 What else does Spring Framework solve

Problem 1 : Duplication/Plumbing Code

integrated with other sub module of spring as below
  • Spring JDBC
  • Spring MVC
  • Spring AOP
  • Spring ORM
  • Spring JMS
  • Spring Test
Provides below advantages:
  • Reduce Boilerplate Code/ Reduce Duplication
  • Promote Decoupling/ Increase Unit Testablity

Problem 2 : Good Integration with Other Frameworks

  • Hibernate for ORM
  • iBatis for Object Mapping
  • JUnit & Mockito for Unit Testing

What is the advantage of spring boot over spring

Advantages of Spring Boot:
  • It is very easy to develop Spring Based applications with Java or Groovy. 
  • It reduces lots of development time and increases productivity. 
  • It avoids writing lots of boilerplate Code, Annotations and XML Configuration.

Project management tools

Trello:

https://trello.com/b/spGLsnTL/project-planning

Smartsheet
https://app.smartsheet.com/home?filter=all

Very simple and easy project management tools, 30 days trails version. use your gmail id for registartion.


Spring Subprojects

Spring was a dependency injection frame work only like (GuicePicoContainer,...), but now a days it is a total solutions for building you Enterprise Application.


Spring now has lots of projects, each with some sub projects (http://spring.io/projects) . When some one speaks about spring, you must find out what spring project he is talking about, is it only spring core, which is known as spring framework, or it is another spring projects.
Some spring projects which is worth too mention are:
If you need some more specify feature for your application, you may find it there too:
  • Spring Batch batch framework designed to enable the development of
    batch application
  • Spring HATEOAS easy creation of REST api based on HATEOAS principal
  • Spring Mobile and Spring Andriod for mobile application development
  • Spring Shell build a full featured shell ( aka command line) application
  • Spring Cloud and Spring Cloud Data Flow for cloud applications
There are also some tiny projects there for example spring-social-facebook(http://projects.spring.io/spring-social-facebook/)
You can use spring for web development as it has the Spring MVC module which is part of Spring Framework project. Or you can use spring with another web frame work, like struts2.

what is Spring framework

Basically Spring is a framework for  which is a pattern that allows to build very decoupled systems


The problem

For example, suppose you need to list the users of the system and thus declare an interface called UserLister:
public interface UserLister {
    List<User> getUsers();
}
And maybe an implementation accessing a database to get all the users:
public class UserListerDB implements UserLister {
    public List<User> getUsers() {
        // DB access code here
    }
}
In your view you'll need to access an instance (just an example, remember):
public class SomeView {
    private UserLister userLister;

    public void render() {
        List<User> users = userLister.getUsers();
        view.render(users);
    }
}
Note that the code above doesn't have initialized the variable userLister. What should we do? If I explicitly instantiate the object like this:
UserLister userLister = new UserListerDB();
...I'd couple the view with my implementation of the class that access the DB. What if I want to switch from the DB implementation to another that gets the user list from a comma-separated file (remember, it's an example)? In that case I would go to my code again and change the last line by:
UserLister userLister = new UserListerCommaSeparatedFile();
This has no problem with a small program like this but... What happens in a program that has hundreds of views and a similar number of business classes. The maintenance becomes a nightmare!

Spring (Dependency Injection) approach

What Spring does is to wire the classes up by using an XML file or annotations, this way all the objects are instantiated and initialized by Spring and injected in the right places (Servlets, Web Frameworks, Business classes, DAOs, etc, etc, etc...).
Going back to the example in Spring we just need to have a setter for the userLister field and have either an XML file like this:
<bean id="userLister" class="UserListerDB" />

<bean class="SomeView">
    <property name="userLister" ref="userLister" />
</bean>
or more simply annotate the filed in our view class with @Inject:
@Inject
private UserLister userLister;
This way when the view is created it magically will have a UserLister ready to work.
List<User> users = userLister.getUsers();  // This will actually work
                                           // without adding any line of code
It is great! Isn't it?
  • What if you want to use another implementation of your UserLister interface? Just change the XML
  • What if don't have a UserLister implementation ready? Program a temporal mock implementation of UserLister and ease the development of the view
  • What if I don't want to use Spring anymore? Just don't use it! Your application isn't coupled to it. Inversion of Control states: "The application controls the framework, not the framework controls the application".
 Also Spring has several good subprojects like Spring MVC, Spring WebFlow, Spring Security and Spring Batch..etc