idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行

1、第一次使用Maven和SSH框架,并且对Idea也是最近两天才使用的,从网上找各种资料,奋战了3个晚上终于搭建好了,由于不经常用,所以需要做好记录以备不时之需,使用的Idea版本是2018.1.5,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第1张图片

2、在上图使用Create New Project创建你一个工程,然后选择Maven,并将Create from archetype打上对勾,然后选择maven-achetype-webapp,如下图所示,然后点击Next

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第2张图片

3、输入GroupId和ArtifactId名称,然后Next,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第3张图片

4、一直Next,然后输入工程名以及选择工程位置,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第4张图片

5、点击Finish后Maven就会创建相应的目录,并且在右下角弹出一个框,然后选择Enable Auto-Import,注意如果不选这个,当向pom.xml添加jar包时不会自动下载和更新,要手动才行,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第5张图片

6、当第一次使用Maven创建项目时会下载一下公共的jar包,时间估计会比较长,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第6张图片

7、当下载完成之后就会创建相应的目录,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第7张图片

8、开始向pom.xml添加jar包依赖,首先要知道加入什么包,然后打开Maven仓库搜索,Maven的仓库地址为:http://mvnrepository.com/ 搜索org.hibernate,就会列出相应的信息,如下图所示:选择Hibernate ORM Hibernate Core。

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第8张图片

9、打开Hibernate Core的各种版本,选择其中一个版本,注意最好不要选最新的,否则有些可能依赖不了,选择5.3.1Final,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第9张图片

10、然后在选择Maven就可以看到dependency信息,这些信息就是pom.xml所需要的,然后选择这些复制,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第10张图片

12、将信息粘贴到pom.xml中dependencies信息中,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第11张图片

13、用相同方法向pom.xml添加相应的jar包,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第12张图片

14、pom.xml文件内容如下:




  4.0.0

  webapp
  webapp
  1.0-SNAPSHOT
  war

  webapp Maven Webapp
  
  http://www.example.com

  
    UTF-8
    1.7
    1.7
  

  
    
      junit
      junit
      4.11
      test
    
    
    
    
      org.hibernate
      hibernate-core
      5.3.1.Final
    
    
    
    
      org.apache.struts
      struts2-core
      2.5.14.1
    
    
    
    
      org.apache.struts
      struts2-spring-plugin
      2.5.14.1
    
    
    
    
      org.springframework
      spring-core
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-context
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-jdbc
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-beans
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-web
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-expression
      5.0.6.RELEASE
    
    
    
      org.springframework
      spring-orm
      5.0.6.RELEASE
    
    
    
      cglib
      cglib
      3.2.6
    
    
    
    
      org.aspectj
      aspectjrt
      1.9.0
    
    
    
      org.aspectj
      aspectjweaver
      1.9.0
    
    
    
    
      mysql
      mysql-connector-java
      8.0.11
    
    
    
      com.mchange
      c3p0
      0.9.5.1
    
  

  
    webapp
    
      
        
          maven-clean-plugin
          3.0.0
        
        
        
          maven-resources-plugin
          3.0.2
        
        
          maven-compiler-plugin
          3.7.0
        
        
          maven-surefire-plugin
          2.20.1
        
        
          maven-war-plugin
          3.2.0
        
        
          maven-install-plugin
          2.5.2
        
        
          maven-deploy-plugin
          2.8.2
        
      
    
  

15、如果不会自动从Maven下载依赖包,那么可手动下载和更新,选择项目右键单击,然后选择Maven->Reimport,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第13张图片

16、新建放置java代码的目录,在src下新建一个Directory目录,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第14张图片

17、创建一个java目录后,可能还不能创建包,需要将java设置为Sources Root目录,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第15张图片

18、设置好之后就可以创建Package了,如下图所示:


19、创建resources用于存放spring和Struts的配置文件,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第16张图片

20、要设置成Resources Root属性才会自动去resources目录寻找配置文件,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第17张图片

21、创建spring的配置文件,创建方法如下:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第18张图片

22、输入spring配置文件的名称:applicationContext.xml,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第19张图片

23、创建好了applicationContext.xml文件后的内容如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第20张图片

24、创建相应的包,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第21张图片

25、向applicationContext.xml添加配置信息,我先一步一步添加,最后会将整个文件的代码贴出来,如下代码:

    
    
    
添加之后如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第22张图片

26、添加后会出现Namespace ‘context’is not bound component-scan is not bound,只需要在xmlns:xsi下添加一行

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

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第23张图片

27、向applicationContext.xml添加bean配置连接数据库的配置信息,如下图所示:是通过文件的方式引入,然后可以通过${jdbc.proerties文件中的名称}来引用所配置的信息,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第24张图片

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 =
如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第25张图片

29、此时applicationContext.xml文件中已经正确引入了jdbc.properties文件,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第26张图片

30、接着向applicationContext.xml添加sessionFactory的bean,此项主要是向hibernate配置数据源,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第27张图片

31、添加hibernate事务管理,代码如下:


id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    name="sessionFactory" ref="sessionFactory"/>

<tx:annotation-driven transaction-manager="txManager"/>

如下图所示会出现annotation-driven is not bound:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第28张图片

32、只需要在文件头部添加:

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

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第29张图片

33、此时已经不在提示错误,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第30张图片

34、开始新建Struts的配置文件struts.xml,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第31张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第32张图片

35、创建好的配置文件如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第33张图片

36、在配置文件中添加Struts的相关信息,代码如下:


name="struts.objectFactory" value="spring" />


name="user" extends="struts-default" namespace="/">
    name="user_*" class="userAction" method="{1}">

        name="success">/index.jsp
        m1,saveUser
    
如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第34张图片

37、使用mysql创建一个数据库,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第35张图片

38、创建一个表,字段分别为:uid,uname,如下图所示:此处最好是设置一个主键,否则之后生成代码时会出现问题,在这里先不创建主键,看看生成的代码会有什么问题

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第36张图片

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

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第37张图片

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

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第38张图片

41、开始在Idea中连接数据库,首先找到右边侧边栏中的Database,然后点击+号,选择DataSource,最后选择Mysql,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第39张图片

42、输入数据库名,user和密码,也可以点击Test Connection测试连接情况,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第40张图片

43、如果Test Connection不能选择,说明没有装mysql驱动,可点击Download进行下载,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第41张图片

44、开始下载mysql驱动,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第42张图片

45、点击Test Connection会出现是否成功,如下图所示表示连接成功。

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第43张图片

46、查看左下角侧边栏是否有Persistence,如下图所示没有。

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第44张图片

47、然后打开File->Project Structure然后选择Modules,依次选择+号的Hibernate,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第45张图片

48、此时Persistence就会出现了,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第46张图片

49、点击之后可以看到在applicationContext.xml添加sessionFactory出现了,如果没有出现,说明配置错误,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第47张图片

50、右键单击选择Generate Persistence Mapping->ByDatabase Schema,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第48张图片

51、选择连接的数据库,输入包的位置,并依次选择相应的信息,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第49张图片

52、在弹出的对话框中选择Yes,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第50张图片

53、此时就会在model生成一个java文件和xml文件,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第51张图片

54、查看User文件内容,此文件内容是自动生成,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第52张图片

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文件删除在表中创建主键之后再重新生成,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第53张图片

57、将applicationContext.xml生成的内容删除,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第54张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第55张图片

58、在表中创建主键,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第56张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第57张图片

59、由于创建主键后要重新连接数据或者删除重新创建,在此是删除重新建立,删除方法如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第58张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第59张图片

60、重新生成代码,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第60张图片

61、此时就不会出现错误,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第61张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第62张图片

62、也会自动在applicationContext.xml插入创建的信息,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第63张图片

63、如果在Import Database Schema中没有sessionFactory可选(出现这种情况可能是由于applicationContext.xml文件中没有配置sessionFactory),如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第64张图片

64、此时查看Project Structure中是否有相应的配置,如果没有则需要添加sessionFactory,如果在导入时还是没有要重新弄查看一下applicationContext.xml文件是否配置正确,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第65张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第66张图片

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的关闭,写了反而会报错
    }
}

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第67张图片

67、在service包中创建UserService接口类,代码如下:

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

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第68张图片

68、在service包中创建一个impl包,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第69张图片

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);
    }
}

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第70张图片

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;
    }
}

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第71张图片

71、在web.xml创建拦截器,代码如下:

  
    contextConfigLocation
    classpath:applicationContext.xml
  


  
    struts2
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  

  
    struts2
    /*
  

  
    org.springframework.web.context.ContextLoaderListener
  

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第72张图片

72、在index.jsp文件中添加入下代码:

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



    ssh测试



<%-- 获取值栈中的user对象的uname的值--%>
用户名: 

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第73张图片

73、再次检查jdbc.properties和applicationContext.xml中的连接的数据库是否正确,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第74张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第75张图片

74、打开Run配置运行的服务,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第76张图片

75、创建Tomcat服务,如下图所示,具体创建方法请看:https://blog.csdn.net/sunxiaoju/article/details/80961289

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第77张图片

76、输入Name,然后选择启动的浏览器,还有一个错误,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第78张图片

77、点击Fix后选择webapp:war如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第79张图片

78、创建之后会在Deployment出现一个栏目,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第80张图片

79、然后点击Run->Debug

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第81张图片

80、然后选择创建好的webapp,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第82张图片

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)
	

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第83张图片

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第84张图片

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
如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第85张图片

83、然后重启tomcat,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第86张图片

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 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 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:53 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:54 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:54 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:54 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:54 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:55 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:55 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:55 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:55 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:55 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:56 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:56 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:56 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:56 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:56 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:57 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:57 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:57 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:57 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:57 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:58 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:58 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:58 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:58 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:58 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.

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第87张图片

85、打开jdbc.properties文件在连接串后加入:&useSSL=false,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第88张图片

86、再次重新启动tomcat,此时出现如下错误信息:

Connected to server
14-Jul-2018 00:14:30.386 信息 [RMI TCP Connection(3)-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...
14-Jul-2018 00:14:31.818 信息 [MLog-Init-Reporter] com.mchange.v2.log.MLog. MLog clients using java 1.4+ standard logging.
14-Jul-2018 00:14:31.876 信息 [RMI TCP Connection(3)-127.0.0.1] com.mchange.v2.c3p0.C3P0Registry. Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]
14-Jul-2018 00:14:34.511 信息 [RMI TCP Connection(3)-127.0.0.1] com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource. Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 20, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge0yy9w156jsmv14c6cg3|23d82eb0, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge0yy9w156jsmv14c6cg3|23d82eb0, idleConnectionTestPeriod -> 0, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql://localhost:3306/webapp?useUnicode=true&characterEncoding=utf-8&useSSL=false, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 20, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 5, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
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.
14-Jul-2018 00:14:36.347 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [C:\Tomcat90\webapps\manager]
14-Jul-2018 00:14:36.452 信息 [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:14:36.496 信息 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [C:\Tomcat90\webapps\manager] has finished in [148] ms
14-Jul-2018 00:15:05.073 警告 [C3P0PooledConnectionPoolManager[identityToken->1hge0yy9w156jsmv14c6cg3|23d82eb0]-HelperThread-#2] com.mchange.v2.resourcepool.BasicResourcePool. com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@3f82989d -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 
 java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
	at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:444)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
	at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
	at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138)
	at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125)
	at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
	at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870)
	at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
	at sun.reflect.GeneratedConstructorAccessor28.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:59)
	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:83)
	at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128)
	at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2201)
	at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2225)
	at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1391)
	at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:993)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:852)

意思是使用的数据库是MySQL,驱动是8.0.11,这是由于数据库和系统时区差异所造成的,在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果需要使用gmt+8时区,需要写成GMT%2B8,否则会被解析为空。再一个解决办法就是使用低版本的MySQL jdbc驱动,5.1.28不会存在时区的问题。

如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第89张图片

87、打开jdbc.properties文件在连接串后加入:&serverTimezone=GMT,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第90张图片

88、再次重新启动tomcat即可成功,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第91张图片

89、启动成功后会打开浏览器显示信息,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第92张图片

90、在浏览器中输入:http://localhost:8080/wincom/user_m1即可显示数据库中的信息,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第93张图片

91、更改数据库中的字段值,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第94张图片

92、刷新浏览器,数据库中的字段值就会被更新,如下图所示:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第95张图片

94、tomcat打印信息如下:

idea使用Maven创建web服务,并搭建ssh框架使用tomcat运行_第96张图片

95、几个配置文件如下:

applicationContext.xml文件:



    
    
    

    
    
        
    
    
    
        
        
        
        
        
        
            50
        
        
        
            5
        
        
        
            5
        
        
        
            20
        
        
        
            50
        
        
        
            20
        
    
    
    
        
        
            
        

        
            
                org.hibernate.dialect.MySQLDialect
                true
                true
                update
                true
                true
                
                true
                
                

                3
                jdbc:mysql://localhost:3306/webapp
                com.mysql.jdbc.Driver
            
        
        
            
                classpath:com/wincom/model/User.hbm.xml
            
        
        
            
                com.wincom.model.User
            
        
    
    
    
        
    
    

struts.xml文件:






    
    

    
    
        

            /index.jsp
            m1,saveUser
        
    

jdbc.properties文件:

mysql.driverClassName = com.mysql.jdbc.Driver
mysql.url = jdbc:mysql://localhost:3306/webapp?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
mysql.username = root
mysql.password =

web.xml文件:




  Archetype Created Web Application
  
    contextConfigLocation
    classpath:applicationContext.xml
  


  
    struts2
    org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
  

  
    struts2
    /*
  

  
    org.springframework.web.context.ContextLoaderListener
  


96、从tomcat启动到ssh从页面到到数据库在到前台的执行顺序为:

在tomcat启动时加载顺序:

(1)先读取web.xml

(2)从web.xml读取到信息开始加载applicationContext.xml文件使其springframework和hibernate连接数据库,并且会对类UserDaoImpl和UserServiceImpl通过注解实例化成userService和userDao,(我理解的是:凡是通过@Service的注解的都在实现接口类中都会将实现的接口类实例化成userService和userDao,不知道对不对

(3)从web.xml读取到信息开始加载以及创建Struts过滤,然后会加载struts.xml配置文件并从中读取过滤信息。

(4)从web.xml读取到信息开始org.springframework.web.context.ContextLoaderListener包处于监听状态

(5)当在浏览器中http://localhost:8080/wincom/user_m1时,会去请求后台,此时Struts就会拦截此请求,并进行解析是否通过,由于Struts.xml文件中的action是user_*,因此只要是user_开头的都会通过,并调用对应的class="userAction" method="{1}"方法,此处的意思是调用通配符为1的方法,通配符就是*号,表示为m1,因此会去调用userAction类中的的m1方法。此时UserAction中有一个注解为userAction,则就表示调用的是UserAction中的m1方法

(6)而在UserAction类中有一个@Resource,并且下边有定义private UserService userService;,那么此时就会从@Resource注解列表中查找是否有userService对象,由于在第二步已经实例化了一个对象,因此在@Resource中就直接将userService对象赋值给当前的userService,那么在此使用userService调用的就会是UserServiceImpl中的方法

(7)在m1方法方法中调用了userService.getUser(1);即调用了UserServiceImpl类中的getUser方法。

(8)而在UserServiceImpl类中同样有注解,userDao就是UserDaoImpl类的实例化对象,那么在getUser方法中又有userDao.getUser(uid)方法进行调用,那么此时就会去调用UserDaoImpl类中的getUser方法

(9)在UserDaoImpl类中又有注解@Resource(name="sessionFactory"),此时就会去applicationContext.xml文件中找sessionFactory,sessionFactory是hibernate通过springframework框架自动生成的一个SessionFactory对象。

(10)SessionFactory在Hibernate中实际上起到了一个缓冲区的作用 他缓冲了HIbernate自动生成SQL语句和其他的映射数据 还缓冲了一些将来有可能重复利用的数据,也就是Hibernate完全是面向对象的写法,不需要写sql语句,直接将值填写到自动生成与表对应的对象中去,然后save(user)即可将值保存到数据库中,在读取时只需要get(User.class,uid)即可返回一个User对象,可通过此对象获取数据库中对应uid的值

(11)此时在UserDaoImpl类中getUser返回一个User对象,然后又返回到UserServiceImpl类中,最后返回到UserAction类的m1方法中,然后UserAction有一个getUser返回user

(12)此时在index.jsp中,那么user即是UserAction类中的user对象,而user.uname就表示值,同时也是数据库中的值。

到此完结,此内容主要参考的是:

http://www.mamicode.com/info-detail-2128475.html

你可能感兴趣的:(java)