Authentication “Who are you?” & Authorization “What can you do?” can be managed using Spring Security. Here we will see a simple example of using Spring Security to authenticate and/or authorize a user to access Spring MVC controller.
Content negotiation in Spring MVC allows you to view data in different format based on the request media type. Here we will see how to view the same data in different media types “json, xml, pdf & excel”.
First step to use Spring in your Java application, is to create Spring configuration metadata, this metadata tells Spring what beans “Java classes” you need to be instantiated in Spring container. You have three options to write or code your configuration metadata “XML, annotation or Java configuration”
How to prepare Spring configuration metadata using XML, annotation or Java based configuration?
Spring framework provides a good way to write “Event-Driven” application! Using Spring we can code our own “custom event” or extends standard ones.
It would be nice to have annotations for events!
- How to develop Spring custom event, how to publish it and how to listen to it?
We can enable the environment-aware feature “Profile” in Spring XML configuration, also we can enable this feature using annotation @Profile in Spring @Configuration class “the Spring annotation configuration” which is equivalent to XML configuration <beans…>…..</beans>.
- How to use @Profile to load Spring configuration for specific environment?
If you like to load environment specific spring configuration you can do this using profile. In other words, if you want to load a set of beans that have different settings on different environment (development, testing or production) you can use profile feature instead of pointing to a different spring xml configuration at each stage.
- How to use profile in spring xml configuration?
We have seen in Mybatis + Spring (XML | Annotation) Mapper how to write a simple mybatis-spring app and what is actually needed to get it up and running. Here I will extend that sample code to cover more stuff that you may face in a real “coding”. We will see how to make a single select that will fetch the one and the many of a “one-to-many” relationship, who to use mybatis config file with spring (if you need it), how to test mybatis-spring code using junit and things you need to watch out!
H2 embedded database has been used to make this example easy to run. But you still can use it with other databases e.g. “MySql, Oracle,….”
- How to use make a single select that will fetch all one to many records?
- How to reference mybatis config file in spring xml config file?
- How to test using junit?
jQuery-File-Upload js library is “so far” the most elegant, smart, simple..etc js library I have used to upload files. Simply it is amazing. It supports async upload “Ajax”, multiple files upload, drag&drop, progress update and a lot more. Here we will see an example of uploading multiple files to Spring MVC app. Bootstrap has been used in this example to make the UI more attractive.
- How to upload single or multiple files using jquery.fileupload.js?
Here we will see what we need to do to connect to a relational database “MySql, Oracle, H2..etc” using myBatis with Spring framework & how to implement mappers using xml or annotation such as @Select, @Insert,….etc. For the sake of simplicity I have used H2 embedded database so you can run the sample code. However, you can use this sample code to run with MySql or any other relational database.
Source Code @ github
Note: If you have Maven you can run this sample code directly using ../spring-mybatis>mvn exec:java
- How to use MyBatis with Spring framework?
- How to implement mapper using xml or annotation @Select, @Insert…?
You can upload files to Spring MVC app in many different ways. For the server side, using MultipartHttpServletRequest is the easiest way to get uploaded files. For the client side we have different options, traditional synchronous method “using html form with submit” or asynchronous method by using Ajax.
- How to receive uploaded files “Multipart” using Spring MVC?
- How to upload files synchronously “HTML Form and Submit Button”?
- How to upload files asynchronously using JQuyer.ajax or FormData object?