Category Archives: JAVA

Maven (http://repo1.maven.org/maven2/): Failed to transfer file and PKIX path building failed: sun.secu

<?xml version="1.0" encoding="UTF-8"?>
 
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
 
<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
 
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
  <!-- Create your own download jar package address
  <localRepository>D:\mavens\LocalWarehouse</localRepository>-->
  <!-- The default address for downloading jar packages-->
  <localRepository>F:\Maven\repository</localRepository>
 
 
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->
 
  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->
 
  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
 
  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
 
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
 
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>
 
  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
 <mirrors>
	 <!-- maven official mirror -->
	<!--
<mirror>
<id>mirrorId</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name </name>
<url>http://repo1.maven.org/maven2/</url>
</mirror><-->

<!-- another mirror -->
<!--
	<mirror> 
	<id>alimaven</id> 
	<name>aliyun maven</name> 
	<url>http://central.maven.org/maven2</url> 
	<mirrorOf>central</mirrorOf> 
	</mirror>

    <mirror> 
    <id>Central</id>   
    <url>http://repo1.maven.org/maven2</url>   
    <mirrorOf>central</mirrorOf>
    </mirror>    


	<mirror> 
	<id>junit</id> 
	<name>junit Address</name> 
	<url>http://jcenter.bintray.com/</url> 
	<mirrorOf>central</mirrorOf> 
	</mirror>
-->

	<mirror> 
	<id>alimaven</id> 
	<name>aliyun maven</name> 
	<url>http://maven.aliyun.com/nexus/content/repositories/central/</url> 
	<mirrorOf>central</mirrorOf> 
	</mirror>



  </mirrors>

 
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>
      <activation>
        <jdk>1.4</jdk>
      </activation>
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
 
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
 
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
 
</settings>

Spring MVC uses Ajax to submit requests asynchronously to complete login

Submit the form asynchronously with Ajax, log in and return the JSON data.

1、 Effect

2、 Configuration

springmvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.it.springmvc" />

    <mvc:annotation-driven></mvc:annotation-driven>
    <bean id="jspViewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <mvc:default-servlet-handler/>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" 
version="3.0">
  <display-name>springMVC</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
      <servlet-name>example</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/springmvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>example</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


</web-app>

Controller

PersonController.java

package com.it.springmvc.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.it.springmvc.entity.Person;

@Controller
public class PersonController {
    @RequestMapping(value="/toLogin",method=RequestMethod.GET)
    public String toLogin(){
        return "login";
    }

    @RequestMapping(value="/login",method=RequestMethod.POST)
    public String login(Person person){
        if(10025==person.getPid()&&"123".equals(person.getPwd())){
            return "redirect:queryAll";
        }else{
            return "login";
        }
    }
    @RequestMapping(value="/queryAll",method=RequestMethod.GET)
    public ModelAndView queryAll(){
        ModelAndView mav=new ModelAndView("show");
        List<Person> list=new ArrayList<Person>();
        list.add(new Person(10025, "tom", "123"));
        list.add(new Person(10026, "jakson", "123"));
        list.add(new Person(10027, "nikly", "123"));
        mav.addObject("list", list);
        return mav;
    }
    @RequestMapping("/ajax")
    @ResponseBody
    public Object ajax(Person person){
        System.out.println(person.getPid()+person.getPwd());
        if(10025==person.getPid()&&"123".equals(person.getPwd())){
            return "{\"flag\":true}";
        }else{
            return "{\"flag\":false}";

        }

    }

}

1.2.2.

Index.jsp

<body>
<%
response.sendRedirect("toLogin");
%>
</body>

login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function(){
    $("#sub").click(function(){
        $.post("ajax",$("form").serialize(),function(data){
            //alert(data.flag);
              if(data.flag){
                alert("Login success");
                location.href="queryAll";
            }else{
                alert("please recheck your usename and password");
            } 
        },'json');
    })
})
</script>
<body>
<form  method="post">
    <table border="1" width="300px">
        <tr>
            <td>usename</td>
            <td><input type="text" name="pid"/></td>
        </tr>
        <tr>
            <td>password</td>
            <td><input type="password" name="pwd"/></td>
        </tr>
        <tr>            
            <!-- <td colspan="2"><input type="submit" value="submit"/></td> -->
            <td colspan="2"><input type="button" value="submit" id="sub"/></td>
        </tr>
    </table>
</form>

</body>
</html>

show.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<a href="toAdd">Add</a>
<table border="1" width="400px">
    <tr>
        <th>NUM</th>
        <th>name</th>
        <th>password</th>
        <th>Act</th>
    </tr>
    <c:forEach var="person" items="${list}">
        <tr>
            <td>${person.pid }</td>
            <td>${person.pname }</td>
            <td>${person.pwd }</td>
            <td><a href="">Update</a></td>
            <td><a href="">DEL</a></td>

        </tr>
    </c:forEach>
</table>
</body>
</html>

[Solved] Java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

1. The startup project reported this error, and the corresponding package was not found, so you need to download the package from the remote warehouse to the local warehouse.

  1 [INFO] Scanning for projects...
  2 [INFO] 
  3 [INFO] -------------------< com.taotao:taotao-manager-web >--------------------
  4 [INFO] Building taotao-manager-web 0.0.1-SNAPSHOT
  5 [INFO] --------------------------------[ war ]---------------------------------
  6 [INFO] 
  7 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ taotao-manager-web ---
  8 [INFO] Deleting D:\eclipse\workspace_taotao\taotao-manager-web\target
  9 [INFO] 
 10 [INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ taotao-manager-web >>>
 11 [INFO] 
 12 [INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ taotao-manager-web ---
 13 [INFO] Using 'UTF-8' encoding to copy filtered resources.
 14 [INFO] Copying 2 resources
 15 [INFO] 
 16 [INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ taotao-manager-web ---
 17 [INFO] Changes detected - recompiling the module!
 18 [INFO] Compiling 1 source file to D:\eclipse\workspace_taotao\taotao-manager-web\target\classes
 19 [INFO] 
 20 [INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ taotao-manager-web <<<
 21 [INFO] 
 22 [INFO] 
 23 [INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ taotao-manager-web ---
 24 [INFO] Running war on http://localhost:8081/
 25 [INFO] Creating Tomcat server configuration at D:\eclipse\workspace_taotao\taotao - manager - web\target\tomcat
  26  [ INFO ] create webapp with contextPath :  
 27 August 03 ,  2019  9 : 06 : 47 AM org . apache . coyote . AbstractProtocol init
  28 Information : Initializing ProtocolHandler [ " Bio-8081-HTTP " ] 
 29 Bayue 03 ,  2019  9 : 06 : 47Morning ORG . The Apache . Catalina . Core . StandardService startInternal
  30 Information : Starting Tomcat Service
  31 Bayue 03 ,  2019  9 : 06 : 47 am ORG . The Apache . Catalina . Core . StandardEngine startInternal
  32 Information : Starting Servlet Engine : the Apache Tomcat / 7.0 . 47 
 33 August 03 ,  2019 9:06:57 AM org.apache.catalina.core.ApplicationContext log
 34 Message: No Spring WebApplicationInitializer types detected on classpath
 35 log4j:WARN No appenders could be found for logger (org.springframework.web.context.support.StandardServletEnvironment).
 36 log4j:WARN Please initialize the log4j system properly. 
 37 log4j : WARN See http : / / logging . Apache . Org / log4j / 1.2 / faq . Html#noconfig for more info . 
 38 August 03 ,  2019  9 : 06 : 58 AM org . apache . Catalina . Core . ApplicationContext log
  39 information : Initializing Spring FrameworkServlet'taotao -manager-web'
 40 August 03 ,  2019  9 : 09 : 33 am org . apache . Catalina . Core . ApplicationContext log
  41 serious : StandardWrapper . Throwable
  42 java . Lang . NoClassDefFoundError : org / apache / commons / fileupload / FileItemFactory
  43      at java . Lang . Class .getDeclaredMethods0(Native Method)
 44     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
 45     at java.lang.Class.getDeclaredMethods(Class.java:1975)
 46     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
 47     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
 48     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
 49     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
 50     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
 51     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
 52     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
 53     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
 54     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
 55     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
 56     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
 57     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
 58     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
 59     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
 60     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
 61     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
 62     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
 63     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
 64     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
 65     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
 66     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
 67     at javax.servlet.GenericServlet.init(GenericServlet.java:160)
 68     at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
 69     at org.apache.catalina.core.StandardWrapper.loadServlet ( StandardWrapper . java : 1193 ) 
 70      at org . apache . catalina . core . StandardWrapper . load ( StandardWrapper . java : 1088 ) 
 71      at org . apache . catalina . core . StandardContext . loadOnStartup ( StandardContext . java : 5176 ) 
 72      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
 73     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 74     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
 75     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
 76     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 77     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 78     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 79     at java.lang.Thread.run(Thread.java:748)
 80 Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
 81     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
 82     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
 83     ... 37 more
 84 
 85 Agu 03, 2019 9:09:33 AM org.apache.catalina.core.StandardContext loadOnStartup
 86 Warning: Servlet  threw load() exception
 87 java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
 88     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
 89     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
 90     at java.lang.Class.getDeclaredMethods0(Native Method)
 91     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
 92     at java.lang.Class.getDeclaredMethods(Class.java:1975)
 93     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
 94     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
 95     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
 96     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
 97     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
 98     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
 99     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
100     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
101     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
102     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
103     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
104     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
105     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
106     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
107     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
108     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
109     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
110     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
111     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
112     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
113     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136 ) 
114      at javax . servlet . GenericServlet . init ( GenericServlet . java : 160 ) 
115      at org . apache . catalina . core . StandardWrapper . initServlet ( StandardWrapper . java : 1280 ) 
116      at org . apache . catalina . core . StandardWrapper . loadServlet(StandardWrapper.java:1193)
117     at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
118     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
119     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
120     at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
121     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
122     at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
123     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
124     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
125     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
126     at java.lang.Thread.run(Thread.java:748)
127 
128 Agu 03, 2019 9:09: 33 am org . Apache . Coyote . AbstractProtocol start
 129 Information : Starting ProtocolHandler [ "http-bio-8081" ] 
130 August 03 ,  2019  9 : 11 : 26 am org . apache . Catalina . Core . ApplicationContext log
 131 information : Initializing Spring FrameworkServlet'taotao -manager-web' 
132 August 03 ,  2019  9:11:26 AM org.apache.catalina.core.ApplicationContext log
133 Warning: StandardWrapper.Throwable
134 java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
135     at java.lang.Class.getDeclaredMethods0(Native Method)
136     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
137     at java.lang.Class.getDeclaredMethods(Class.java:1975)
138     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
139     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
140     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
141     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
142     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
143     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
144     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
145     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
146     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
147     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
148     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
149     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
150     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
151     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
152     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
153     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
154     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
155     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
156     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
157     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
158     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
159      at javax . servlet . GenericServlet . init ( GenericServlet . java : 160 ) 
160      at org . apache . catalina . core . StandardWrapper . initServlet ( StandardWrapper . java : 1280 ) 
161      at org . apache . catalina . core . StandardWrapper . loadServlet (StandardWrapper.java:1193)
162     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
163     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
164     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
165     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
166     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
167     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
168     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
169     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
170     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
171     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
172     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
173     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
174     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
175     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
176     at java.lang.Thread.run(Thread.java:748)
177 Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
178     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
179     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
180     ... 42 more
181 
182 Agu 03, 2019 9:11:26 AM org.apache.catalina.core.StandardWrapperValve invoke
183 WANING: Allocate exception for servlet taotao-manager-web
184 java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
185     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
186     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
187     at java.lang.Class.getDeclaredMethods0(Native Method)
188     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
189     at java.lang.Class.getDeclaredMethods(Class.java:1975)
190     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
191     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
192     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
193     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
194     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
195     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
196     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
197     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
198     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
199     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
200     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
201     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
202     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
203     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
204     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
205     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
206     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
207     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
208     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
209     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
210     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
211     at javax.servlet.GenericServlet.init(GenericServlet.java:160)
212     at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
213     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
214     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
215     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
216     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
217     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
218     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
219     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
220     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
221     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
222     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
223     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
224     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
225     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
226     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
227     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
228     at java.lang.Thread.run(Thread.java: 748 ) 
229  
230 August 03 ,  2019  9 : 11 : 27 AM org . apache . Catalina . Core . ApplicationContext log
 231 Information : Initializing Spring FrameworkServlet'taotao -manager-web' 
232 August 03 ,  2019  9 : 11 : 27 AM org . Apache . Catalina . Core . ApplicationContext log
 233 WANING: StandardWrapper.Throwable
234 java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
235     at java.lang.Class.getDeclaredMethods0(Native Method)
236     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
237     at java.lang.Class.getDeclaredMethods(Class.java:1975)
238     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
239     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
240     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
241     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
242     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
243     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
244     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
245     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
246     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
247     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
248     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
249     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
250     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
251     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
252     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
253     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
254     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
255     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
256     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
257     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
258     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
259     at javax.servlet.GenericServlet.init(GenericServlet.java:160)
260      at org . apache . catalina . core . StandardWrapper . initServlet ( StandardWrapper . java : 1280 ) 
261      at org . apache . catalina . core . StandardWrapper . loadServlet ( StandardWrapper . java : 1193 ) 
262      at org . apache . catalina . core . StandardWrapper.allocate(StandardWrapper.java:865)
263     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
264     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
265     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
266     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
267     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
268     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
269     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
270     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
271     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
272     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
273     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
274     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
275     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
276     at java.lang.Thread.run(Thread.java:748)
277 Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
278     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
279     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
280     ... 42 more
281 
282 Agu 03, 2019 9:11:27 AM org.apache.catalina.core.StandardWrapperValve invoke
283 WANING: Allocate exception for servlet taotao-manager-web
284 java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
285     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
286     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
287     at java.lang.Class.getDeclaredMethods0(Native Method)
288     at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
289     at java.lang.Class.getDeclaredMethods(Class.java:1975)
290     at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:609)
291     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:521)
292     at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:507)
293     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241)
294     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069)
295     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042)
296     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
297     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
298     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
299     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
300     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
301     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
302     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
303     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
304     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
305     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
306     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
307     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
308     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
309     at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
310     at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
311     at javax.servlet . GenericServlet . init ( GenericServlet . java : 160 ) 
312      at org . apache . catalina . core . StandardWrapper . initServlet ( StandardWrapper . java : 1280 ) 
313      at org . apache . catalina . core . StandardWrapper . loadServlet ( StandardWrapper . java :1193)
314     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
315     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
316     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
317     at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
318     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
319     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
320     at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
321     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
322     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
323     at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
324     at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
325     at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
326     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
327     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
328     at java.lang.Thread.run(Thread.java:748)

Just add dependencies.

1 <dependencies>
2     <!-- File upload component -->
3     <dependency>
4         <groupId>commons-fileupload</groupId>
5         <artifactId>commons-fileupload</artifactId>
6     </dependency>
7 </dependencies>

Java Error: No enclosing instance of type Main is accessible. Must qualify the allocation with an encl

The following error occurred today while compiling a Java program.
No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main).
The source code I originally wrote looked like this

public class Main 
{
class Dog
{
private String name;
private int weight;
public Dog(String name, int weight) 
{
this.setName(name);
this.weight = weight;
}
public int getWeight() 
{
return weight;
}
public void setWeight(int weight) 
{this.weight = weight;}
public void setName(String name)
{this.name = name;}
public String getName() 
{return name;}
}
public static void main(String[] args)
{
Dog d1 = new Dog("dog1",1);

}
}

When this error occurred, I didn’t quite understand it.

After learning from other people’s explanation, I suddenly realized.

In the code, my dog class is an internal class defined in main. The dog inner class is dynamic, while my main method is static.

Just as static methods cannot call dynamic methods.

There are two solutions:

Method 1

Define the inner class dog as a static class.

Method 2

Define the inner class dog outside the main class.

Mongodb java version 3.X, prompt “XXX (an encryption algorithm) is not available” when there is a user name and password

First of all, describe the project environment: Maven + mongodb-java-driver-3.2.2

The original project was written with Mongo 2. X driver, and then upgraded to 3. X. The first big change is user name and password verification.

This is the way to get mongoclient.


import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;

/**
 * MongoDBUtils
 * @author administration
 *
 */
public class DBUtil {

	/**
	 * Connect to mongoDB with username password (MongoCredential method)
	 * @param mongodbAddr
	 * @param databaseName
	 * @return
	 */
	public static MongoClient getMongoClientByCredent(String mongodbAddr, String databaseName){
		MongoClient mongoClient;
		Properties p = TDTFile.getProperAddr("db.properties");
		String user = p.getProperty("username");
		String pswd = p.getProperty("password");
		List<ServerAddress> serverAddrList = new ArrayList<ServerAddress>();
		ServerAddress serverAddress = new ServerAddress(mongodbAddr);
		serverAddrList.add(serverAddress);
		List<MongoCredential> credentialList = new ArrayList<MongoCredential>();
		MongoCredential credential = MongoCredential.createCredential(user, databaseName, pswd.toCharArray());
		credentialList.add(credential);
		mongoClient = new MongoClient(serverAddrList, credentialList);
		return mongoClient;
	}
	
	/**
	 * Connect to mongoDB with username password (URI method)
	 * @param mongodbAddr
	 * @param databaseName
	 * @return
	 */
	public static MongoClient getMongoClientByURI(String mongodbAddr, String databaseName){
		MongoClient mongoClient;
		Properties p = TDTFile.getProperAddr("db.properties");
		String user = p.getProperty("username");
		String pswd = p.getProperty("password");
		//System.out.println(user + "," + pswd);
		String uri = String.format("mongodb://%s:%s@%s/%s", user, pswd, mongodbAddr, databaseName);
		System.out.println(uri);
		MongoClientURI mongoClientURI = new MongoClientURI(uri);
		mongoClient = new MongoClient(mongoClientURI);
		return mongoClient;
	}
	
}

Two ways are no problem, run well in eclipse. But!! After packaging with MVN package, it can’t be used. After a night and a day’s analysis, I locked the root cause of the error in the statement that the command line executed the command. My sentence is like this:

java -Djava.ext.dirs=../lib Other parameters

The problem lies in the – D parameter. Baidu knows that – D is equivalent to setting external environment variables. Since my main method relies on many third-party jar packages, it seems that there is nothing wrong with it. But it ignores a problem, that is

After using the – D parameter to specify other directories, Java needs to load% Java_ The jar package in the home% \ JRE/lib/ext directory is no longer loaded!! I searched the usage of – D parameter on the Internet for a long time, but no one mentioned it.. But it’s hard for me. One day is wasted here..

 

Solution:

Package the required external dependent packages, including some packages such as JDK’s own encryption algorithm, into lib with Maven. Problem solving. By the way, the algorithm package required by mongodb3. X is% Java_ HOME%\jre\lib\ext\sunjce_ provider.jar

 

Java Error | Error:java: Compilation failed: internal java compiler error

Background

Error:java: Compilation failed: internal java compiler error

According to previous experience, the compiling environment of the read project is reset, and the JDK version is all specified as 1.8
1. Setting – & gt; Java complier

2.Project Structure->Modules

After the above steps are set, the same error will be reported in the recompile run

Solution

After investigation, the project Pom.xml The file does not specify a compiled version, in the Pom.xml Add the following plug-ins:

<build>

    <plugins>
        <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>
    </plugins>

</build>

The precision of decimal calculation with double and float in Java is not accurate

The precision of decimal calculation with double and float in Java is not accurate

In most cases, using double and float to calculate the result is accurate, but in some systems with high accuracy requirements or known decimal calculation results will not be accurate, this problem is very serious.

《Effective Java “refers to a principle, that is, float and double can only be used for scientific calculation or engineering calculation, but we should use them in commercial calculation java.math.BigDecimal By using the BigDecimal class, we can solve the above problems. The designer of Java provides a very useful class BigDecimal for programmers, which can improve the problem that the float and double classes can’t calculate accurately I’m sorry.

The example code is as follows:

package ex;

import java.math.*;

public class BigDecimalDemo {
    public static void main(String[] args){
        System.out.println(ArithUtil.add(0.01, 0.05));
        System.out.println(ArithUtil.sub(1.0, 0.42));
        System.out.println(ArithUtil.mul(4.015, 100));
        System.out.println(ArithUtil.div(123.3, 100));
    }
}

class ArithUtil{
    private static final int DEF_DIV_SCALE=10;

    private ArithUtil(){}
    //+
    public static double add(double d1,double d2){
        BigDecimal b1=new BigDecimal(Double.toString(d1));
        BigDecimal b2=new BigDecimal(Double.toString(d2));
        return b1.add(b2).doubleValue();

    }
    //-
    public static double sub(double d1,double d2){
        BigDecimal b1=new BigDecimal(Double.toString(d1));
        BigDecimal b2=new BigDecimal(Double.toString(d2));
        return b1.subtract(b2).doubleValue();

    }
    //*
    public static double mul(double d1,double d2){
        BigDecimal b1=new BigDecimal(Double.toString(d1));
        BigDecimal b2=new BigDecimal(Double.toString(d2));
        return b1.multiply(b2).doubleValue();

    }
    // /
    public static double div(double d1,double d2){

        return div(d1,d2,DEF_DIV_SCALE);

    }

    public static double div(double d1,double d2,int scale){
        if(scale<0){
            throw new IllegalArgumentException("The scale must be a positive integer or zero");
        }
        BigDecimal b1=new BigDecimal(Double.toString(d1));
        BigDecimal b2=new BigDecimal(Double.toString(d2));
        return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();

    }

}

Now let’s analyze in detail why floating-point operations cause precision loss?

1. Binary representation of decimals

 First we need to clarify the following two issues.

     (1) How to convert decimal integers to binary numbers

           The algorithm is simple. As an example, 11 is expressed as a binary number.

                     11/2=5 remainder 1

                       5/2=2 remainder 1

                       2/2=1 remainder 0

                       1/2=0 remainder 1

                          End of 0 11 is represented in binary as (from bottom to top):1011

          In other words, will the algorithm for converting all integers into binary numbers go on indefinitely? Absolutely not, integers can always be represented exactly in binary, but not decimals.

      (2) How decimal decimals are converted into binary numbers

           The algorithm is to multiply by 2 until there are no more decimals. As an example, 0.9 is expressed as a binary number

                     0.9*2=1.8 Take the integer part 1

                     0.8(fractional part of 1.8)*2=1.6 Take the integer part 1

                     0.6*2=1.2 Take the integer part 1

                     0.2*2=0.4 Take the integer part 0

                     0.4*2=0.8 Take integer part 0

                     0.8*2=1.6 Take integer part 1

                     0.6*2=1.2 Take integer part 0

                              .........      0.9 Binary representation (from top to bottom): 1100100100100 ......

           Note: The above calculation process is circular, which means that *2 can never eliminate the fractional part, so that the algorithm will go on indefinitely. Obviously, the binary representation of decimals is sometimes impossible to be exact. The reason is simple: can 1/3 be represented accurately in the decimal system? This explains the loss of precision in floating-point subtraction, where "subtraction is incomplete". 

.
2. Storage of float type in memory

It is well known that Java's float type takes up 4 bytes in memory. float's 32 binary bits are structured as follows



float memory storage structure

             4bytes 31 30 29 ----23 22 ----0         

                        Indicates real sign bit Exponential sign bit Exponential bit Valid number of bits

        Where the sign bit 1 means positive and 0 means negative. The valid bits are 24 bits, one of which is the real sign bit.

         The steps to convert a float type to memory storage format are

        (1) First convert the absolute value of this real number into binary format, noting that the binary methods for the integer and decimal parts of the real number have been discussed above. 
     (2) Shift the decimal point of this binary format real number left or right by n bits until the decimal point moves to the right of the first significant digit. 
     (3) Count out twenty-three digits from the first digit to the right of the decimal point into the 22nd to the 0th digit. 
     (4) If the real number is positive, put a "0" in the 31st place, otherwise put a "1". 
     (5) If n is shifted to the left, the exponent is positive and "1" is placed in the 30th place. If n is shifted to the right or n=0, then "0" is placed in the 30th position. 
     (6) If n is obtained by left shift, n is converted to binary by subtracting 1 and adding "0" to the left to make up the seven bits and put it into the 29th to 23rd place. If n is shifted to the right or n=0, then n is converted to binary and "0" is added to the left to make up the seven bits, and then each bit is inverted and placed in bits 29 to 23.

          Example: Memory storage format of 11.9

       (1) The memory storage format of 11.9 is approximately "1011. 11100110011001100110011001100..." after converting 11.9 to binary. .".

       (2) Shift the decimal point three places left to the right of the first significant digit: "1. 011 11100110011001100110". Ensure that the number of significant digits is 24, with the extra intercept on the right (where the error is created ).

       (3) This already has twenty-four valid digits, remove the leftmost "1" to get "011 11100110011001100110" with 23 bits. (4) Since 11.9 is a valid number, it is a valid number.

       (4) Since 11.9 is a positive number, put "0" in the 31st real sign bit.

       (5) Since we are shifting the decimal point to the left, we put "1" in the 30th exponent sign position.

       (6) Since we are shifting the decimal point 3 places to the left, we subtract 1 from 3 to get 2, convert it to binary, and add 7 bits to get 0000010, and put it in the 29th to 23rd place.

           The final representation of 11.9 is: 0 1 0000010 011 11100110011001100110

           Another example: the memory storage format of 0.2356
      (1) After converting 0.2356 to binary, it is approximately 0.00111100010100000100100000. 
      (2) Move the decimal point three places to the right to get 1.11100010100000100100000. 
      (3) Count out twenty-three valid digits from the right of the decimal point, i.e. 1110001010100000100100000.
into the 22nd to the 0th digit. 
      (4) Since 0.2356 is positive, put a "0" in the 31st place. 
      (5) Since we have shifted the decimal point to the right, we put a "0" in the 30th place. 
      (6) Because the decimal point is shifted to the right by 3 bits, so the 3 is converted to binary, and the "0" is added to the left to make up the full seven
(6) Because the decimal point is shifted to the right by 3 bits, the 3 is converted to binary, and the "0" is added to the left to make up the seven bits to get 0000011. 


           The final value of 0.2356 is: 0 0 1111100 11100010100000100100000

          Steps to convert a memory-stored float binary format to decimal. 
     (1) Write out the binary number from the 22nd to the 0th digit, and add a "1" to the leftmost digit to get twenty-four valid digits. Put the decimal point to the right of the leftmost "1". 
     (2) Take out the value n from the 29th to the 23rd digit, and invert the n digit when the 30th digit is "0". When the 30th digit is "1", increment n by 1. 
     (3) Shift the decimal point left by n (when the 30th digit is "0") or right by n (when the 30th digit is "1") to obtain a real number in binary. 
     (4) Convert this binary real number to decimal and add a plus or minus sign depending on whether the 31st bit is a "0" or a "1". 

3. Subtraction of floating point

The process of adding and subtracting floating point is more complex than the process of fixed point. The process of completing a floating point addition or subtraction operation is roughly divided into four steps.

(1) Checking of the 0 operand.
        If one of the two floating-point numbers to be added or subtracted is 0, the result of the operation is known without the need to perform some sequential operations. 

(2) Comparing the magnitude of the ordinal (exponent bits) and completing the pair order.
    To add or subtract two floating-point numbers, we must first see whether the exponent bits of the two numbers are the same, i.e., whether the decimal point positions are aligned. If the two numbers have the same exponent, it means the decimal points are aligned, and the addition and subtraction of the last number can be performed. On the contrary, if the two numbers have different ordinates, it means that the decimal points are not aligned, so we must make the ordinates of the two numbers the same, and this process is called pairing.

    How to pair order (assuming two floating point numbers with exponent bits Ex and Ey ).
    By shifting the mantissa to change Ex or Ey so that they are equal. Since floating point numbers are mostly speciated, shifting the trailing left number will cause the loss of the highest significant bit, resulting in a large error; while shifting the trailing right number will cause the loss of the lowest significant bit, but the error caused is smaller, therefore, the pairwise order operation requires that the trailing right number be shifted, and after the trailing right number is shifted, the order code is increased accordingly, while its value remains unchanged. Obviously, if one of the increased ordinals is equal to the other, the increased ordinal must be a small one. Therefore, in the order pairing, always make the small order to the large order, that is, the end of the small order shift to the right (equivalent to the decimal point left shift), each right shift one, its order code plus 1, until the two numbers of the order code equal, the number of right shift is equal to the order difference △ E. 

(3) The mantissa (valid digits) is added or subtracted.

(4) The result is normalized and rounded.

Twitter’s distributed self increasing ID algorithm snowflake (Java version)

summary

In distributed systems, there are some scenarios where a globally unique ID is needed. In this case, in order to prevent ID conflicts, a 36 bit UUID can be used. However, UUID has some disadvantages. First, it is relatively long. In addition, UUID is generally unordered.

Sometimes we want to use a simpler ID, and we want the ID to be generated in time order.

Twitter’s snowflake solved this problem. At first, twitter migrated the storage system from Mysql to Cassandra. Because Cassandra had no sequential ID generation mechanism, it developed such a global unique ID generation service.

structure

The structure of each part is as follows:

0 – 0000000000 0000000000 0000000000 0000000000 0 – 00000 – 00000 – 000000000000

The first bit is unused, the next 41 bits are milliseconds (the length of 41 bits can be used for 69 years), then 5-bit datacenterid and 5-bit workerid (the length of 10 bits can support deployment of 1024 nodes at most), and the last 12 bits are counts within milliseconds (the 12 bit counting sequence number supports 4096 ID serial numbers per millisecond for each node)

A total of 64 bits, a long type. (length of converted string is 18)

The IDs generated by snowflake are sorted according to the time increment, and there is no ID collision (distinguished by datacenter and workerid) in the whole distributed system, and the efficiency is high. It is said that snowflake can generate 260000 IDS per second.

Source code

(Java version of the source)

/**
 * Twitter_Snowflake<br>
 * The structure of SnowFlake is as follows (each part is separated by -):<br>
 * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
 * 1-bit identifier, as the long basic type is signed in Java, the highest bit is the sign bit, positive numbers are 0, negative numbers are 1, so the id is generally positive, the highest bit is 0 <br>
 * 41-bit time intercept (milliseconds), note that the 41-bit time intercept is not a time intercept to store the current time, but the difference between the time intercept (current time intercept - start time intercept)
 * the value obtained), where the start time intercept, generally our id generator to start using the time specified by our program (the following program IdWorker class startTime property). 41-bit time intercept, you can use 69 years, year T = (1L << 41)/(1000L * 60 * 60 * 24 * 365) = 69<br>
 * 10-bit data machine bits that can be deployed in 1024 nodes, including 5-bit datacenterId and 5-bit workerId<br>
 * 12-bit sequential, millisecond counting, 12-bit counting sequence number supports 4096 ID sequential numbers per node per millisecond (same machine, same time cutoff)<br>
 * Add up to exactly 64 bits for a Long type. <br>
 * The advantage of SnowFlake is that the overall self-increasing sorting by time and no ID collision within the whole distributed system (distinguished by data center ID and machine ID), and high efficiency, tested, SnowFlake can generate about 260,000 IDs per second.
 */
public class SnowflakeIdWorker {

    // ==============================Fields===========================================
    /** Start time cutoff (2015-01-01) */
    private final long twepoch = 1420041600000L;

    /* The number of bits occupied by the machine id */
    private final long workerIdBits = 5L;

    /* The number of bits occupied by the data identifier id */
    private final long datacenterIdBits = 5L;

    /* The maximum machine id supported, resulting in 31 (this shift algorithm can quickly calculate the maximum number of decimal digits that can be represented by a few binary digits) */
    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);

    /* The maximum supported data identifier id, resulting in 31 */
    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);

    /** The number of bits in the id that the sequence occupies */.
    private final long sequenceBits = 12L;

    /** The machine ID is shifted 12 bits to the left */.
    private final long workerIdShift = sequenceBits;

    /** The data identifier id is shifted to the left by 17 bits (12+5)*/.
    Private final long datacenterIdShift = sequenceBits + workerIdBits。

    /** The time truncation is shifted to the left by 22 bits (5+5+12) */.
    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits。

    /** Generate the mask for the sequence, here 4095. (0b111111111111=0xfff=4095) */
    private final long sequenceMask = -1L ^ (-1L << sequenceBits);

    /** Work machine ID(0~31) */
    private long workerId;

    /** Work machine ID(0~31) */
    private long datacenterId;

    /** Intra-millisecond sequence (0~4095) */
    private long sequence = 0L;

    /** Time cutoff of the last generated ID */
    private long lastTimestamp = -1L;

    //==============================Constructors=====================================
    /**
     * Constructor
     * @param workerId Job ID (0~31)
     * @param datacenterId datacenterId (0~31)
     */
    public SnowflakeIdWorker(long workerId, long datacenterId) {
        if (workerId > maxWorkerId || workerId < 0) {
            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
        }
        if (datacenterId > maxDatacenterId || datacenterId < 0) {
            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
        }
        this.workerId = workerId;
        this.datacenterId = datacenterId;
    }

    // ==============================Methods==========================================
    /**
     * Get the next ID (this method is thread-safe)
     * @return SnowflakeId
     */
    public synchronized long nextId() {
        long timestamp = timeGen();

        //If the current time is less than the timestamp of the last ID generation, it means that the system clock is backed off and an exception should be thrown at this time
        if (timestamp < lastTimestamp) {
            throw new RuntimeException(
                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
        }

        //If it was generated at the same time, then perform a sequence within milliseconds
        if (lastTimestamp == timestamp) {
            sequence = (sequence + 1) & sequenceMask;
            // sequence overflow in milliseconds
            if (sequence == 0) {
                //Block until the next millisecond, get the new timestamp
                timestamp = tilNextMillis(lastTimestamp);
            }
        }
        //Timestamp change, sequence reset in milliseconds
        else {
            sequence = 0L;
        }

        //Time cutoff of the last generated ID
        lastTimestamp = timestamp;

        //Shifted and put together by orthogonal operations to form a 64-bit ID
        return ((timestamp - twepoch) << timestampLeftShift) //
                | (datacenterId << datacenterIdShift) //
                | (workerId << workerIdShift) //
                | sequence;
    }

    /**
     * Block to the next millisecond until the new timestamp is obtained
     * @param lastTimestamp Time cutoff of the last generated ID
     * @return currentTimestamp
     */
    protected long tilNextMillis(long lastTimestamp) {
        long timestamp = timeGen();
        while (timestamp <= lastTimestamp) {
            timestamp = timeGen();
        }
        return timestamp;
    }

    /**
     * Returns the current time in milliseconds
     * @return current time in milliseconds
     */
    protected long timeGen() {
        return System.currentTimeMillis();
    }

    //==============================Test=============================================
    /** TEST */
    public static void main(String[] args) {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
        for (int i = 0; i < 1000; i++) {
            long id = idWorker.nextId();
            System.out.println(Long.toBinaryString(id));
            System.out.println(id);
        }
    }
}

“21442;” 32771;

Java uses single thread pool to realize multi thread sequential execution (non alternating, non synchronous)

1. Principle and mechanism

Use one-way pool to ensure orderly submission and execution.

explain:

1) Alternate execution between threads is not supported.

2) Multithreading is not synchronous, only to ensure the order of execution, multithreading is concurrent execution.

2. Code examples

package com.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class TasksWithoutLockTest extends Thread {

    private static int num = 0;
    private int id;

    public TasksWithoutLockTest(int id) {
        this.id = id;
    }


    @Override
    public void run() {
        System.out.println("Thread" + id + "output num:" + num++);
        try {
            Thread.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //ExecutorService exec = Executors.newFixedThreadPool(1);
        ExecutorService exec = Executors.newSingleThreadScheduledExecutor();
        for (int i = 0; i < 12; i++) {
            exec.submit(new TasksWithoutLockTest(i));
        }

        exec.shutdown();

    }
}

3. Output results

Asynchronous processing of HTTP request by Java_ Method 2: through deferredresult

1.DeferredResult

Spring supports HTTP asynchronous return

2. Asynchronous processing

Start a new thread, process the data and return the value.

3. Code examples

1)controller

package com.liuxd.controller;

import com.liuxd.entity.Responses;
import com.liuxd.service.TaskService2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;

@Slf4j
@RestController
public class AsyncCtr2 {

    @Autowired
    private TaskService2 taskService2;

    @GetMapping(value = "/getResult")
    public DeferredResult<Responses<String>> getResult() {
        log.info("HTTP request received...");
        long startTime = System.currentTimeMillis();

        DeferredResult<Responses<String>> deferredResult = new DeferredResult<Responses<String>>();

        new Thread(new Runnable() {
            @Override
            public void run() {
                taskService2.getData(deferredResult);
            }
        }).start();

        log.info("The task of the receiving HTTP request thread has been completed, exit!");
        long endTime = System.currentTimeMillis();
        log.info("http Total request time. " + (endTime - startTime) + "ms");

        return deferredResult;

    }
}

2)service

package com.liuxd.service;

import com.liuxd.entity.Responses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

@Slf4j
@Service
public class TaskService2 {

    public void getData(DeferredResult<Responses<String>> deferredResult) {

        log.info("Call service asynchronous with return method, start execution...");
        long startTime = System.currentTimeMillis();

        try {
            Thread.sleep(2500L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        log.info("Call service asynchronous has return method, the end of execution!!!") ;

        long endTime = System.currentTimeMillis();
        log.info("Total time taken to call service asynchronous return method. " + (endTime - startTime) + "ms");

        deferredResult.setResult(new Responses<>(0, "Done", "SUCCESS"));

    }


}

3)Responses

package com.liuxd.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Responses<T> {

    private Integer code;

    private String msg;

    private T data;

}

4) Print results

5) Result analysis

1) The HTTP main thread accepts the request and ends after processing the request

2) After the asynchronous thread ends, returns the