The SSM framework integration swagger and adminlte of Java High concurrency kill system API

Source: Internet
Author: User

Original intention and arrangement description

Java high concurrent Kill system API is a Java project from the online tutorial, and I am the first project to touch Java. Originally a C # code farm, the company plans to part of the business to Java, so I use business time to self-study Java has this article, originally contacted to listen to others, C # To turn Java is easy, I also believe, but really to learn the time or step on countless pits, good friends have a few to do Android, Asked them some experience, but they do the Android and the Web is two directions, so continue to a person silently mining pit to avoid thunder, first of all, the following is the Java high Concurrency system API.

The purpose of Learning Java is a company change, the second is that they want to learn to see, increase the thickness of the next technology, more understanding of the different programming languages, different implementation methods. In order to get through the two veins of the governor. Before also saw the python thing, but the interest is not big, Java after all, the ecology is very good, various great gods many, each language also has the different advantages and disadvantages, the more understanding is advantageous to own development.

About this second kill system garden already have several big God wrote related article, actually did not want to caught dead, right vote as a study note to see it, the focus is on this system integration swagger and adminlte, why integrate them, because I have been in the C#.net project has done related content,
Abp+adminlte+bootstrap table Rights Management system Phase I, haha, self-marketing, interested friends can take a look at the way to go?
Originally thought that swagger UI and Adminlte integration will be very simple, but the hands to do the time to find a lot of problems, because I was holding first to write a Web project to do the original intention to do, after I did find a lot of problems, in fact, the most important problem is the foundation is not strong, shake, After writing this article, I decided to learn from the basics and learn a bit more deeply. Includes but is not limited to like tomcat,servlet,webservice,mybatis,maven,spring,spring boot,spring cloud.

Use

Don't say much nonsense, open the whole. About the configuration of the Java development environment I will not pull, online tutorial a lot of, say MAVEN configuration, first to download the official website http://maven.apache.org/download.cgi


Then the configuration of the system variables

Path configuration

Then win+r the shortcut cmd into the DOS window, enter the command, MVN-V (note there is a space in the middle), after the run can see MAVEN version maven home indicates the installation is successful

Maven Auto-Build Project

Finally, enter the following command on the command line: MVN archetype:generate-dgroupid=cn.codingxiaxw.seckill-dartifactid=seckill-dpackage= Cn.codingxiaxw.seckill-dversion=1.0-snapshot-darchetypeartifactid=maven-archetype-webapp
Note in the two carriage return, start I just waited a long time no response, view Item no,
The carriage return here probably means the default DgroupId and DartifactId.


Then open the address on the command line above and see the following file stating that the project was successfully generated.


Idea Open does not complete the project structure as follows.

Next configure Tomcat.

Configured to open localhost:8080 can see the relevant effect, here to pay attention to a big pit, especially the first into Java friends, such as.

An error that always reports invalid tokens. Finding a big circle on the internet doesn't fit my mistakes. Finally I downloaded the jdk1.8 version and solved it, the problem is that idea and JDK 9.0 conflict in the project. Problem solved I did not go to the bottom of the question, I guess there are other problems. At that time, various problems were excluded, the code checked n times, never thought it was a JDK error.

Pom.xml and GitHub Address

Then is the configuration Pom.xml, the code is very long I will not post it, go directly to my GitHub pom.xml to see: https://github.com/Jimmey-Jiang/seckill/blob/master/seckill/ Pom.xml, this includes the introduction of the Swaggerui to be said later.

Basic Business Writing

Next is to follow the tutorial step by step writing. Includes Dto,entity,dao,service,web, controller, view, test class, JSP writing. I will not say, go to my GitHub on the clone down to open to see it, or to see the tutorial bar.

Preliminary effect

The results are as follows.

Swagger integration

Other code tutorials are available, and finally focus on the integration of swagger.
The first of course is to download swagger, then introduce the project, and then modify the URL inside the index.html to Http://localhost:8080/api-docs.

Pom introduces a jar package. Swagger gets the API to return the data in JSON form to the Swagger UI, where Jackson's related packages need to be introduced

    <!--swagger-->    <dependency>      <groupId>com.mangofactory</groupId>      <artifactId>swagger-springmvc</artifactId>      <version>1.0.2</version>    </dependency>    <dependency>      <groupId>com.fasterxml.jackson.core</groupId>      <artifactId>jackson-annotations</artifactId>      <version>2.4.4</version>    </dependency>    <dependency>      <groupId>com.fasterxml.jackson.core</groupId>      <artifactId>jackson-databind</artifactId>      <version>2.4.4</version>    </dependency>    <dependency>      <groupId>com.fasterxml.jackson.core</groupId>      <artifactId>jackson-core</artifactId>      <version>2.4.4</version>    </dependency>

Build config package, and then create a new Swaggerconfig configuration class

Package org.seckill.config;/** * Created by Jiangcy on 2018/1/23. */import Com.mangofactory.swagger.configuration.springswaggerconfig;import Com.mangofactory.swagger.models.dto.apiinfo;import Com.mangofactory.swagger.plugin.enableswagger;import Com.mangofactory.swagger.plugin.swaggerspringmvcplugin;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.context.annotation.Bean; Import Org.springframework.context.annotation.configuration;import ORG.SPRINGFRAMEWORK.WEB.SERVLET.CONFIG.ANNOTATION.ENABLEWEBMVC, @Configuration @enableswagger@enablewebmvcpublic    Class Swaggerconfig {private Springswaggerconfig springswaggerconfig; /** * Required to Autowire springswaggerconfig */@Autowired public void Setspringswaggerconfig (Springswagge    Rconfig springswaggerconfig) {this.springswaggerconfig = Springswaggerconfig; }/** * Every Swaggerspringmvcplugin bean is picked up by the SWAGGER-MVC * framework-allowing for MultipLe swagger groups i.e. same Code base * Multiple Swagger resource listings. */@Bean public swaggerspringmvcplugin customimplementation () {return new Swaggerspringmvcplugin (THIS.SPR    Ingswaggerconfig). Apiinfo (Apiinfo ()). IncludePatterns (". *?"); } private Apiinfo Apiinfo () {apiinfo apiinfo = new Apiinfo ("Swagger test", "Test query                User "," Developer: Changxin L "," [email protected] "," MIT License ",        "/license");    return apiinfo; }}

Then we configure the mapping path of the static resource in the configuration class.

    <!-- 将 springSwaggerConfig加载到spring容器 -->    <bean     class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />    <!-- 将自定义的swagger配置类加载到spring容器 -->    <bean class="org.seckill.config.SwaggerConfig" />        <mvc:resources mapping="/swagger/**" location="/WEB-INF/swagger/"/>    <!-- 定义无需Controller的url<->view直接映射 -->    <mvc:view-controller path="/" view-name="../WEB-INF/swagger/index"/>
Swagger effect

If the above operation is correct, then you will see the following interface:

Adminlte with other

The introduction of Adminlte is much simpler, without the need for a jar package, just to introduce static resources.
So do not do the statement, the need can be a clone project to see.

The SSM framework integration swagger and adminlte of Java High concurrency kill system API

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.