Spring is a good frame ... One common problem with Java development, however, is that it is too cumbersome to configure earlier. With a new project on hand, I decided to do it in Java, see the new Spring 4, and spring Boot, to make a quick Web Demo. But I don't really like the way I use annotations so much, and Spring 4 comes out a little too soon, so I'm going to do it with spring.
Spring 3 Configuration More, many online articles will teach you step by step to build the environment, involving details is how to say all have. Another uncomfortable point is that some concepts are unclear and unfriendly to the first-time users. Plus my memory is not good, and do not want to start a new project again from the beginning to learn again, so did a Maven archetype, put on Github, named Spring-webapp-restful-quickstart, as the name implies, in addition to support the WEB, You can also support RESTful APIs, like this:
- Http://localhost:8080/index
This is the HTML page output
- Http://localhost:8080/index.json
This is the output of the JSON data
The above two output only depends on the URL suffix, internal use is the same controller--do not separate for the API dedicated Controller.
API output uses Contentnegotiatingviewresolver, currently the API only supports JSON format output, but to add other formats, such as XML is not difficult, you can change the Applicationcontext.xml The configuration is good.
This skeleton uses Tiles 2 as a template, choose Tiles 2 because it uses JSP as the base language, it is better to use with other tag libraries, and for those familiar with Java to expand it is easier to do their own JSP tag on the line. As for why not choose Tiles 3 ... Because I look at the Tiles 2 feature is enough, no longer see Tiles 3 ... The Jetty is also configured so that you can run the project directly with Maven Jetty:run.
At the moment this archetype just put it on my Github, and after that, some more will be released to the Maven central repository. If you need to, just git clone and install it to the local MAVEN repository using MAVEN installer. Remember to choose Spring-webapp-restful-quickstart when creating a new project with Maven.
Quickly build Web apps with Spring (RESTful API support)