1. 程式人生 > >idea使用Maven建立web服務,並搭建ssh框架使用tomcat執行

idea使用Maven建立web服務,並搭建ssh框架使用tomcat執行

1、第一次使用Maven和SSH框架,並且對Idea也是最近兩天才使用的,從網上找各種資料,奮戰了3個晚上終於搭建好了,由於不經常用,所以需要做好記錄以備不時之需,使用的Idea版本是2018.1.5,如下圖所示:


2、在上圖使用Create New Project建立你一個工程,然後選擇Maven,並將Create from archetype打上對勾,然後選擇maven-achetype-webapp,如下圖所示,然後點選Next


3、輸入GroupId和ArtifactId名稱,然後Next,如下圖所示:


4、一直Next,然後輸入工程名以及選擇工程位置,如下圖所示:


5、點選Finish後Maven就會建立相應的目錄,並且在右下角彈出一個框,然後選擇Enable Auto-Import,注意如果不選這個,當向pom.xml新增jar包時不會自動下載和更新,要手動才行,如下圖所示:


6、當第一次使用Maven建立專案時會下載一下公共的jar包,時間估計會比較長,如下圖所示:


7、當下載完成之後就會建立相應的目錄,如下圖所示:


8、開始向pom.xml新增jar包依賴,首先要知道加入什麼包,然後開啟Maven倉庫搜尋,Maven的倉庫地址為:http://mvnrepository.com/ 搜尋org.hibernate,就會列出相應的資訊,如下圖所示:選擇Hibernate ORM Hibernate Core。


9、開啟Hibernate Core的各種版本,選擇其中一個版本,注意最好不要選最新的,否則有些可能依賴不了,選擇5.3.1Final,如下圖所示:


10、然後在選擇Maven就可以看到dependency資訊,這些資訊就是pom.xml所需要的,然後選擇這些複製,如下圖所示:


12、將資訊貼上到pom.xml中dependencies資訊中,如下圖所示:


13、用相同方法向pom.xml新增相應的jar包,如下圖所示:


14、pom.xml檔案內容如下:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>webapp</groupId>
  <artifactId>webapp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>webapp Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <!-- 新增Hibernate依賴 -->
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.3.1.Final</version>
    </dependency>
    <!-- struts2 -->
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-core -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>2.5.14.1</version>
    </dependency>
    <!-- struts2 spring  整合的核心包-->
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts2-spring-plugin -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-spring-plugin</artifactId>
      <version>2.5.14.1</version>
    </dependency>
    <!-- spring -->
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>5.0.6.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/cglib/cglib -->
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib</artifactId>
      <version>3.2.6</version>
    </dependency>
    <!--spring aop包  註釋方式使用事務管理 可以不引用-->
    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjrt</artifactId>
      <version>1.9.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
    <dependency>
      <groupId>org.aspectj</groupId>
      <artifactId>aspectjweaver</artifactId>
      <version>1.9.0</version>
    </dependency>
    <!-- 新增對資料庫的支援 -->
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.11</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
    <dependency>
      <groupId>com.mchange</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.5.1</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>webapp</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
15、如果不會自動從Maven下載依賴包,那麼可手動下載和更新,選擇專案右鍵單擊,然後選擇Maven->Reimport,如下圖所示:


16、新建放置java程式碼的目錄,在src下新建一個Directory目錄,如下圖所示:


17、建立一個java目錄後,可能還不能建立包,需要將java設定為Sources Root目錄,如下圖所示:


18、設定好之後就可以建立Package了,如下圖所示:


19、建立resources用於存放spring和Struts的配置檔案,如下圖所示:


20、要設定成Resources Root屬性才會自動去resources目錄尋找配置檔案,如下圖所示:


21、建立spring的配置檔案,建立方法如下:


22、輸入spring配置檔案的名稱:applicationContext.xml,如下圖所示:


23、建立好了applicationContext.xml檔案後的內容如下圖所示:


24、建立相應的包,如下圖所示:


25、向applicationContext.xml新增配置資訊,我先一步一步新增,最後會將整個檔案的程式碼貼出來,如下程式碼:

    <context:component-scan base-package="com.wincom.action"></context:component-scan>
    <context:component-scan base-package="com.wincom.service"></context:component-scan>
    <context:component-scan base-package="com.wincom.dao"></context:component-scan>
新增之後如下圖所示:


26、新增後會出現Namespace ‘context’is not bound component-scan is not bound,只需要在xmlns:xsi下新增一行

xmlns:context="http://www.springframework.org/schema/context"
如下圖所示:


27、向applicationContext.xml新增bean配置連線資料庫的配置資訊,如下圖所示:是通過檔案的方式引入,然後可以通過${jdbc.proerties檔案中的名稱}來引用所配置的資訊,如下圖所示:


28、在resources目錄中建立jdb.poperties檔案,並新增入下資訊:

mysql.driverClassName = com.mysql.jdbc.Driver
mysql.url = jdbc:mysql://localhost:3306/webapp?useUnicode=true&characterEncoding=utf-8
mysql.username = root
mysql.password =
如下圖所示:


29、此時applicationContext.xml檔案中已經正確引入了jdbc.properties檔案,如下圖所示:


30、接著向applicationContext.xml新增sessionFactory的bean,此項主要是向hibernate配置資料來源,如下圖所示:


31、新增hibernate事務管理,程式碼如下:

<!-- 用註解來實現事物管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>

如下圖所示會出現annotation-driven is not bound:


32、只需要在檔案頭部新增:

xmlns:tx="http://www.springframework.org/schema/tx"

如下圖所示:


33、此時已經不在提示錯誤,如下圖所示:


34、開始新建Struts的配置檔案struts.xml,如下圖所示:



35、建立好的配置檔案如下圖所示:


36、在配置檔案中新增Struts的相關資訊,程式碼如下:

<!-- 修改常量管理struts 中的action的工程,這個常量的使用,必須引入 spring和struts的整合包,不然spring無法管理struts2 Action 中的實體類-->
<constant name="struts.objectFactory" value="spring" />
<package name="user" extends="struts-default" namespace="/">
    <action name="user_*" class="userAction" method="{1}">
        <result name="success">/index.jsp</result>
        <allowed-methods>m1,saveUser</allowed-methods><!-- struts 2.5 之後,使用萬用字元必須加上這一行 ,否則無法使用萬用字元訪問-->
</action>
</package>
如下圖所示:


37、使用mysql建立一個數據庫,如下圖所示:


38、建立一個表,欄位分別為:uid,uname,如下圖所示:此處最好是設定一個主鍵,否則之後生成程式碼時會出現問題,在這裡先不建立主鍵,看看生成的程式碼會有什麼問題


39、輸入表名user,如下所示:


40、插入值,如下圖所示:


41、開始在Idea中連線資料庫,首先找到右邊側邊欄中的Database,然後點選+號,選擇DataSource,最後選擇Mysql,如下圖所示:


42、輸入資料庫名,user和密碼,也可以點選Test Connection測試連線情況,如下圖所示:


43、如果Test Connection不能選擇,說明沒有裝mysql驅動,可點選Download進行下載,如下圖所示:


44、開始下載mysql驅動,如下圖所示:


45、點選Test Connection會出現是否成功,如下圖所示表示連線成功。


46、檢視左下角側邊欄是否有Persistence,如下圖所示沒有。


47、然後開啟File->Project Structure然後選擇Modules,依次選擇+號的Hibernate,如下圖所示:


48、此時Persistence就會出現了,如下圖所示:


49、點選之後可以看到在applicationContext.xml新增sessionFactory出現了,如果沒有出現,說明配置錯誤,如下圖所示:


50、右鍵單擊選擇Generate Persistence Mapping->ByDatabase Schema,如下圖所示:


51、選擇連線的資料庫,輸入包的位置,並依次選擇相應的資訊,如下圖所示:


52、在彈出的對話方塊中選擇Yes,如下圖所示:


53、此時就會在model生成一個java檔案和xml檔案,如下圖所示:


54、檢視User檔案內容,此檔案內容是自動生成,如下圖所示:


55、開啟User.hbm.xml檔案,會出現錯誤:

The content of elemnt type "class" must match

"(meta*,subselect?,cache?,synchronize*,comment?tuplizer*(id|composite-id),disciminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-aray)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-upda

這是由於user表沒有建立主鍵引起的,如下圖所示:


56、先把User.java和User.hbm.xml檔案刪除在表中建立主鍵之後再重新生成,如下圖所示:


57、將applicationContext.xml生成的內容刪除,如下圖所示:



58、在表中建立主鍵,如下圖所示:



59、由於建立主鍵後要重新連線資料或者刪除重新建立,在此是刪除重新建立,刪除方法如下圖所示:



60、重新生成程式碼,如下圖所示:


61、此時就不會出現錯誤,如下圖所示:



62、也會自動在applicationContext.xml插入建立的資訊,如下圖所示:


63、如果在Import Database Schema中沒有sessionFactory可選(出現這種情況可能是由於applicationContext.xml檔案中沒有配置sessionFactory),如下圖所示:


64、此時檢視Project Structure中是否有相應的配置,如果沒有則需要新增sessionFactory,如果在匯入時還是沒有要重新弄檢視一下applicationContext.xml檔案是否配置正確,如下圖所示:



65、在dao包中建立一個UserDao介面類,程式碼如下:

package com.wincom.dao;
import com.wincom.model.User;
public interface UserDao {
    User getUser(Integer uid);
    void saveUser(User user);
}

如下圖所示:

66、在dao包中建立一個UserDaoImpl類並實現UserDao介面,程式碼如下:

package com.wincom.dao;
import com.wincom.model.User;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
@Repository("userDao")
public class UserDaoImpl implements UserDao{
    @Resource(name="sessionFactory")
    private SessionFactory sessionFactory;
    public User getUser(Integer uid){
        Session session=sessionFactory.getCurrentSession();
        //當getCurrentSession所在的方法,或者呼叫該方法的方法綁定了事務之後,session就與當前執行緒綁定了,也就能通過currentSession來獲取,否則就不能。
        User user=session.get(User.class,uid);
        return user;
    }
    public void saveUser(User user){
        Session session=sessionFactory.getCurrentSession();
        session.save(user);
        System.out.println("======="+user.getUname());
        //使用getCurrentSession後,hibernate 自己維護session的關閉,寫了反而會報錯
    }
}

如下圖所示:

67、在service包中建立UserService介面類,程式碼如下:

package com.wincom.service;
import com.wincom.model.User;
public interface UserService {
    User getUser(Integer uid);
    void saveUser(User user);
}

如下圖所示:

68、在service包中建立一個impl包,如下圖所示:


69、在impl包中建立一個UserServiceImpl類並實現UserService介面,程式碼如下:

package com.wincom.service.impl;

import com.wincom.model.User;
import com.wincom.service.UserService;
import com.wincom.dao.UserDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@Service("userService")
public class UserServiceImpl implements UserService {
    //依賴Dao
    @Resource
    private UserDao userDao;
    @Transactional(rollbackFor = {Exception.class,RuntimeException.class})
    public User getUser(Integer uid){
        return userDao.getUser(uid);
    }
    // 注入事務管理
    @Transactional(rollbackFor = {Exception.class,RuntimeException.class})
    public void saveUser(User user){
        userDao.saveUser(user);
    }
}

如下圖所示:


70、在action包中建立UserAction類並繼承stauts包中ActionSupport類,程式碼如下:

package com.wincom.action;
import com.wincom.model.User;
import com.opensymphony.xwork2.ActionSupport;
import com.wincom.service.UserService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource;
@Controller("userAction")
@Scope("prototype")
public class UserAction extends ActionSupport {
    private User user;

    @Resource
    private UserService userService;

    public User getUser(){
        return user;
    }
    public String m1(){
        user=userService.getUser(1);
        System.out.println(user.getUname());
        return SUCCESS;
    }
    public String saveUser(){
        User user=new User();
        user.setUname("事務已提交");
        userService.saveUser(user);
        return SUCCESS;
    }
}

如下圖所示:

71、在web.xml建立攔截器,程式碼如下:

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>


  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

如下圖所示:

72、在index.jsp檔案中新增入下程式碼:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%-- 引入struts2 的標籤庫--%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
    <title>ssh測試</title>
</head>
<body>

<%-- 獲取值棧中的user物件的uname的值--%>
使用者名稱: <s:property value="user.uname"></s:property>
</body>
</html>

如下圖所示:


73、再次檢查jdbc.properties和applicationContext.xml中的連線的資料庫是否正確,如下圖所示:



74、開啟Run配置執行的服務,如下圖所示:



76、輸入Name,然後選擇啟動的瀏覽器,還有一個錯誤,如下圖所示:


77、點選Fix後選擇webapp:war如下圖所示:


78、建立之後會在Deployment出現一個欄目,如下圖所示:


79、然後點選Run->Debug

80、然後選擇建立好的webapp,如下圖所示:


81、此時出現錯誤,意思應該是applicationContext.xml檔案中有不能識別的資訊,錯誤資訊:

[2018-07-14 12:06:11,096] Artifact webapp:war: Artifact is being deployed, please wait...
Connected to server
14-Jul-2018 00:06:15.220 資訊 [RMI TCP Connection(2)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
ERROR ContextLoader Context initialization failed
 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 7 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 62; cvc-complex-type.2.4.c: 萬用字元的匹配很全面, 但無法找到元素 'context:component-scan' 的宣告。
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)
	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:621)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4643)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5109)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:742)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:718)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:703)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1737)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:457)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:406)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:287)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:835)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 62; cvc-complex-type.2.4.c: 萬用字元的匹配很全面, 但無法找到元素 'context:component-scan' 的宣告。
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
	at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
	at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:453)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3231)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1912)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:741)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2784)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:842)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
	at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:77)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
	

如下圖所示:

82、只需要在applicationContext.xml檔案的頭部新增入下資訊:

       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx.xsd
如下圖所示:


83、然後重啟tomcat,如下圖所示:


84、此時又出現警告SSH,意思是mysql不推薦伺服器身份驗證,不需要建立SSL連線。根據MySQL 5.5.45 +,+,+ 5.6.26 5.7.6要求SSL連線必須建立明確的選項預設情況下如果不設定。符合現有的應用程式不使用SSL的verifyservercertificate屬性設定為“false”。你需要顯式禁用SSL設定usessl = false,或設定usessl =真實提供伺服器證書驗證信任庫連線,錯誤資訊如下:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Sat Jul 14 00:10:49 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:49 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:49 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:49 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:49 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:50 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
14-Jul-2018 00:10:51.002 資訊 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Tomcat90\webapps\manager]
14-Jul-2018 00:10:51.120 資訊 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
14-Jul-2018 00:10:51.164 資訊 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Tomcat90\webapps\manager] has finished in [161] ms
Sat Jul 14 00:10:51 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:51 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:51 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:51 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:51 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:52 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Sat Jul 14 00:10:52 CST 2018 WARN: Establishing SSL connection without server's identity verification is not reco