How to implement REST API for already developed Spring java Project (it has service and DAO layer alone no controller)
I asked this in general how should implement REST API in spring java project.
I have developed Spring + hibernate project i want to implement REST API on that how can we do that can anyone explain me with an example that should call Service Layer -> DAO Layer to persist or retrieve from DB.
If you are asking a spring-styled framework to export your DB service as a RESTful web service, the spring data rest project may helps you.
I am new to Spring. Can any one let me know what is the difference between Spring and Spring MVC Framework ?
Spring is a big framework, that contains a lot of components. One of these components is Spring MVC - it is a component that lets you implement your web application according to the model-view-controller design pattern.
1- Spring in abstract word is a framework
The Spring Framework is an open source application framework and inversion of control container for the Java platform.
Check this links for more information:
Spring Framework
Framework vs. Toolkit vs. Library
2- MVC architecture
it is an architecture that help the developer to separate the building block of web application.
Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications
check this link for more information:
Basic MVC Architecture
MVC is a Spring module. You use it for designing web applications. MVC in Spring implements the front controller design pattern. In your web.xml you'll define a single servlet (DispatcherServlet) and all your requests will pass through it and will be attended by Controllers you will define (#Controller).
Spring is a framework which helps to connect different components together. There are many modules for IOC, AOP, Web MVC etc.Spring Framework is an open source application framework and inversion of control container for the Java platform.
Spring MVC (Model–view–controller) is one component within the whole Spring Framework, to support development of web applications.
Spring MVC is one component within the whole Spring Framework, to support development of web applications. You can use any web containers, so it works fine with Tomcat. Just think that Spring is a third party library. You just need to put the necessary jar files in the lib directory, and define a few xml files.
So basically when you just say Spring it is a just a framework. And by framework I mean lot of functionalities/jars. Like you may have core which has core functionality or aspectj etc. Spring MVC i.e model view controller is one such functionality offered by Spring framework. You can deffer processing of request to various controllers based on the pattern of URL requested. You can refer
Spring MVC hello world example
Spring framework can be visualized as an alternative to, replacement for, or even addition to the Enterprise JavaBeans (EJB) model as mentioned here. That means a framework to develop distributed, scalable, secured, transactional application.
Spring MVC can be thought of as an replacement to Struts, Stripes, Tapestry etc, i.e. Presentation layer framework.
Spring framework is the super set of Spring MVC.
Spring
An umbrella term to denote various projects, one of which is Spring Framework.
Spring MVC
The Spring Framework project has several features. One of them is Spring MVC.
Features of Spring Framework are -
Core Technologies: Dependency Injection, validation, data binding, type conversion, SpEL, AOP etc.
Testing
Data Access: Transactions, DAO support, JDBC, ORM etc.
Spring MVC and Spring WebFlux web frameworks.
Integration: JMS, JMX, email, scheduling etc.
Languages: Kotlin, Groovy, dynamic languages.
So, the Spring MVC feature allows developers to build applications following Model-view-controller design pattern using Spring Framework.
Other Spring projects
Spring Boot: For creating stand-alone Spring applications using Convention over configuration design paradigm.
Spring Data: For creating Spring-based programming model for data access. It has various modules like Spring Data JDBC, Spring Data JPA, Spring Data MongoDB etc.
Spring Security: Powerful and highly customizable authentication and access-control framework for both Authentication and Authorization.
And many other projects.
NOTE
Spring, Spring Framework and Spring MVC these terms are often used interchangeably among developers which sometimes creates confusion for people who already don't know the details.
I am pretty new to spring and currently I was able to create a complete web service with spring-ws. Now I want to separate the functionalities of my web service in to two separate web services. But except the service layer there are other spring components (business layer) which are common to both of these services.
So my question is there a way to make spring web service depend on another spring project (business layer)? If you can provide such example or a tutorial where a spring web service depends on another spring project it will be really helpful.
Thanks in advance.
UPDATE
I could achieve above by building my business layer as a jar file and adding it as a dependency to the service. But now my supervisor wants me to deploy the business layer in a separate server. But I could not find any information on how to handle communication here between web service and the business layer. Any idea?
I've created a "framework/toolkit" for a specific type of database search. This was done with Spring-Data JPA using hibernate. This framework is usable by standalone desktop app or as a web application.
This framework ships with entity classes, Spring-Data Repositories and a transactional Service layer with optional method level security (spring-security annotations).
now I would like to create a web application using this framework. Since grails is from spring to and also uses hibernate I thought this might work but I'm open to other suggestions.
The entities in the web application will extend such provided by my framework and should use spring-data repositories extending repositories provided by the framework and services extending provided services for data access.
Or said otherwise I'm mainly interested in the scaffolding part (controller and CRUD web pages) and not the data access part. I'm open to any other tools that can achieve this.
Is this possible with grails? Other suggestions? Spring Roo?
I have a classic Java SOA application, with a web UI module, web services module, a service module (Java API), a domain module and a persistence module. In a sense, each of these modules has their own public API.
My understanding of Spring Security is that I can use web filters to handle the security of the web gui and web services, and method level security (via annotations) for the service module.
My question is this: should I bother to add method level security to the domain module and the persistence module or is that considered overkill?
If you secure the external API's it's normally not needed to secure additional internal layers such as the domain model or DAO persistence layer.
But all depends on you're security requirements. Adding security roles to you're methods in the internal API's will make it more secure and can be considered a good defensive practice against security holes in you’re exposed API.