maven Mode of SSM Framework Construction

MAVEN Download and Installation

maven's download address: http://maven.apache.org/download.cgi

Path D: java apache-maven-3.6.2 after decompression;
Add a new system variable [MAVEN_HOME], and replace the variable name with its own local decompression path

Added value of system variable [Path]:%MAVEN_HOME%bin

Run cmd and enter mvn version or mvn v; if you see the figure below, it shows that the maven installation is configured.

Local warehouse configuration file: D: java Apache - Maven - 3.6.2 conf settings. XML
Create a local storage folder repository under the maven directory and set the local storage path D: java Apache - maven - 3.6.2 repository

<localRepository>D:\java\apache-maven-3.6.2\repository</localRepository>

Direct access to maven < local repository > D: java Apache - maven - 3.6.2 repository </local repository > public warehouse is slow, so it is recommended to use Ali's maven warehouse image. Under mirrors node, add the following content

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

Set the default jdk and add the following under the profiles node (you can omit it, as well as the pom.xml configuration)

<profile>
        <id>nexus</id>
        <repositories>
            <repository>
                <id>central</id>
                <url>http://repo.maven.apache.org/maven2</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>ansj-repo</id>
                <name>ansj Repository</name>
                <url>http://maven.nlpcn.org/</url>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
        </repositories>
    </profile>

II. MAVEN Configuration

Maven project directory structure
|----src
| |----main
||| - Java - java files
||| resource - resource File
||| webapp - jsp/html/css/image/js file
| |----test
||| - Java - Testing java files
||| resource - resource File
| - target - project output location
| - pom.xml - the logo of the maven project

eclipse settings Maven
Find the Maven node, User Setting, in Windows - Preferences, and set it as follows:

Click on the Installations node and add maven runtime as shown below

3. Creating Maven Project by eclipse

Click File - - - New - - - Maven Project (default) or File - - - New - - - Other, select the maven folder, and click Maven Project as shown below.

Click Next, select the default workspace location, select the web type, and then click Next

Fill in GroupID, ArtifactID, click Finish to complete the creation of maven project web project
Group ID: Equivalent to an organization
Artifact ID: Equivalent to a specific project under this organization
Packege: Generate a default name based on Group ID and Artifact ID

IV. Modification of Configuration

Right-click on the project to view the project information. The default DNamic Web Module is 2.3 and Tomcat 8.5, which needs to be modified to 3.1.

(1) Find the file org.eclipse.wst.common.project.facet.core.xml in the directory where the maven project is located.

(2) Replace the web.xml file under the Maven project with

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
       version="3.1" metadata-complete="true">
</web-app>

(3). Modify the build node in the pom. XML file and add the following

<plugins>
       <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
              </configuration>
       </plugin>
    </plugins>

(4) Right-click on the project to find the Update Project under the Maven attribute

(5) Select the project to update. If you are afraid that you can't force the update, check Force Update of Snapshots/Releases and check again if the Dynamic Web Module is 3.1 after the update.

Right-click project -- Properties--Deployment Assembly, remove target

V. case test

directory structure

  1. Add the following to Pom.xml
<properties>
        <srping.version>4.0.2.RELEASE</srping.version>
        <mybatis.version>3.2.8</mybatis.version>
        <slf4j.version>1.7.12</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
    </properties>
    <dependencies>
        <!-- spring Framework package start -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.bundles</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.6.8_2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${srping.version}</version>
        </dependency>
        <!-- spring Framework package end -->

        <!-- mybatis Framework package start -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>
        <!-- mybatis Framework package end -->

        <!-- Database Driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.17</version>
        </dependency>
        <!-- Import dbcp Of jar Packet, used in the ____________ applicationContext.xml Configure database in -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>

        <!-- jstl Tag class -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!-- log start -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <!-- log END -->
        <!-- Json -->
        <!-- Format objects to facilitate log output -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.6</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <!-- Upload component packages start -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency>
        <!-- Upload component packages end -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- java ee package -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

2.datasource.properties
The driver name of mysql8 is not com.mysql.jdbc.Driver; pay special attention to url writing

datasource.driverClassName=com.mysql.cj.jdbc.Driver
datasource.userName=root
datasource.userPassword=123456
datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC

3. log4j.properties

#Define LOG output level
log4j.rootLogger=INFO,Console,File

#Define the log output destination as the console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
#You can flexibly specify the log output format. The following line specifies the specific format
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%c]-%m%n

#mybatis shows that the SQL statement log configuration net.cxp.blog.dao is the package name of your Dao interface  
#log4j.logger.org.mybatis=DEBUG
log4j.logger.com.lymn.it.mapper=DEBUG

#Generate a new file when the file size reaches the specified size
log4j.appender.File=org.apache.log4j.RollingFileAppender
#Specify output directory
log4j.appender.File.File=d:/logs/ssm.log
#Define the maximum file size
log4j.appender.File.MaxFileSize=10MB
#Output all logs, if replaced by DEBUG, indicating output of logs above DEBUG level
log4j.appender.File.Threshold=DEBUG
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm|\:ss}][%c]%m%n

4. spring-mvc.xml

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

    <!-- Scanning the package automatically SpringMVC Think the package is used.@controller The annotated class is the controller,This must be ruled out.@Service assembly -->
    <context:component-scan base-package="com.lymn.it.controller" />
    <!-- Will automatically register RequestMappingHandlerMapping And RequestMappingHandlerAdapter Two Bean,This is Spring MVC
    //Required to distribute requests for @Controller. Start the annotation function of Spring MVC and complete the mapping of request and annotation POJO s - >.
    <mvc:annotation-driven/>

    <!-- view resolver -->
    <!-- Define the prefix and suffix of the jumped file, view mode configuration -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- The configuration here is automatic to the back. action Method return The string with prefix and suffix becomes available url address -->
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <!--Access to static resource files -->
    <!-- In the light of springMVC Of restful Style url In terms of configuration -->
    <mvc:resources mapping="/images/**" location="/WEB-INF/images/" />
    <mvc:resources mapping="/css/**" location="/WEB-INF/css/" />

</beans>

5.spring-mybatis.xml

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

    <!-- Configure the scan path with annotations, but not controller -->
    <context:component-scan base-package="com.lymn.it.*">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <!-- PropertyPlaceholderConfigurer yes BeanFactory The implementation of post processor is also BeanFactoryPostProcessor 
    //An implementation of the interface. Allows attribute values in context (configuration file) to be placed in a separate standard Java Properties file. Using EL-like in XML files 
    //The ${key} of the expression replaces the value in the specified properties file - >.
    <!-- <bean id="placeHolder"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:config/datasource.properties"></property>
        //Multiple Data Source Writing
        <property name="locations">
            <list>
                <value>classpath:config/datasource1.properties</value>
                <value>classpath:config/datasource2.properties</value>
            </list>
        </property>
    </bean> -->

    <!-- Spring2.5 Later, a simplified way of introducing external files was introduced. -->
    <context:property-placeholder location="classpath:datasource.properties" />
    <!-- Spring Provided data sources,Create a new connection for each connection request -->
     <bean id="dataSource" 
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${datasource.driverClassName}"></property>
        <property name="url" value="${datasource.url}"></property>
        <property name="username" value="${datasource.userName}"></property>
        <property name="password" value="${datasource.userPassword}"></property>
    </bean>

    <!-- spring and MyBatis Perfect integration, no need mybatis Configuration mapping file -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <!-- scanning entity Packages use aliases -->
        <property name="typeAliasesPackage" value="com.lymn.it.model"></property>
        <!-- To configure MyBaties Global Profile:mybatis-config.xml -->
        <!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> -->
        <property name="dataSource" ref="dataSource" />
        <!-- Automatic scanning mapping.xml file -->
        <property name="mapperLocations" value="classpath:com/lymn/it/mapper/*.xml"></property>
    </bean>
    <!-- mapper The package name of the interface, Spring The following classes are automatically found -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.lymn.it.mapper" />
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <!-- (transaction management)transaction manager -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- Transaction enhancements, which are used here spring Provided features -->
    <tx:advice id="tx" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="select*" read-only="true" />
            <tx:method name="find*" read-only="true" />
            <tx:method name="get*" read-only="true" />
            <tx:method name="has*" read-only="true" />
            <tx:method name="count*" read-only="true" />
            <tx:method name="search*" read-only="true" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="pc"
            expression="execution(* com.lymn.it.service.impl..*.*(..))" />
        <!--Control transactions at Service layer -->
        <aop:advisor pointcut-ref="pc" advice-ref="tx" />
    </aop:config>

</beans>

6.model--User

package com.lymn.it.model;

public class User {
        private Integer userid;
        private String username;
        private String password;
        private String email;
        private String phone;
        private Integer status;
        private String code;
        public Integer getUserid() {
            return userid;
        }
        public void setUserid(Integer userid) {
            this.userid = userid;
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        public String getEmail() {
            return email;
        }
        public void setEmail(String email) {
            this.email = email;
        }
        public String getPhone() {
            return phone;
        }
        public void setPhone(String phone) {
            this.phone = phone;
        }
        public Integer getStatus() {
            return status;
        }
        public void setStatus(Integer status) {
            this.status = status;
        }
        public String getCode() {
            return code;
        }
        public void setCode(String code) {
            this.code = code;
        }
        @Override
        public String toString() {
            return "User [userid=" + userid + ", username=" + username + ", password=" + password + ", email=" + email
                    + ", phone=" + phone + ", status=" + status + ", code=" + code + "]";
        }

}

7.mapper-UserMapper.java

package com.lymn.it.mapper;

import java.util.List;

import com.lymn.it.model.User;

public interface UserMapper {
    public List<User> getAllUsers();

    public User getUserById(int userid);

    public boolean deleteUserById(int userid);

    public boolean insertUser(User user);

    public boolean updateUserById(User user);
}

mapper-UserMapper.java

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lymn.it.mapper.UserMapper">
    <select id="getAllUsers" resultType="User">
        SELECT * FROM user
    </select>
    <select id="getUserById" parameterType="int" resultType="User">
        SELECT *
        FROM user WHERE userid = #{userid}
    </select>
    <insert id="insertUser" parameterType="User"
        useGeneratedKeys="true" keyProperty="userid">
        INSERT INTO s_user(username,password,email,phone)
        VALUES(#{username},#{password},#{email},#{phone})
    </insert>
    <update id="updateUserById" parameterType="User">
        UPDATE user SET username = #{username},
                          password = #{password},
                          email = #{email},
                          phone = #{phone}
                          WHERE 
                          userid = #{userid}
    </update>
    <delete id="deleteUserById" parameterType="int">
        DELETE  FROM user WHERE userid = #{userid}
    </delete>
</mapper>

8.service-UserService.java

package com.lymn.it.service;

import java.util.List;

import com.lymn.it.model.User;

public interface UserService {
    public List<User> getAllUsers();

    public User getUserById(int userid);

    public boolean deleteUserById(int userid);

    public boolean insertUser(User user);

    public boolean updateUserById(User user);
}

service-UserServiceImpl.java

package com.lymn.it.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lymn.it.mapper.UserMapper;
import com.lymn.it.model.User;
import com.lymn.it.service.UserService;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public List<User> getAllUsers() {
        return userMapper.getAllUsers();

    }

    @Override
    public User getUserById(int userid) {
        return userMapper.getUserById(userid);

    }

    @Override
    public boolean deleteUserById(int userid) {
        return userMapper.deleteUserById(userid);

    }

    @Override
    public boolean insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public boolean updateUserById(User user) {
        return userMapper.updateUserById(user);
    }

}

9.controller-UserController

package com.lymn.it.controller;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lymn.it.model.User;
import com.lymn.it.service.UserService;

@Controller
public class UserController {
    @Autowired
    UserService userService;
    Logger logger=Logger.getLogger(UserController.class);
    @RequestMapping(value="/user")
    public String user(Map<Object,Object> map) {
        logger.info("Query all user data");
        List<User> userList =  userService.getAllUsers();
        map.put("user", userList);
        logger.info("When the query is finished, return to the page.");
        return "user";
    }

}

10.web.xml adds the following configuration

<!-- spring Container configuration -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <!-- Be careful, spring Loading configuration files -->
        <param-value>
            classpath:spring-mybatis.xml
        </param-value>
    </context-param>
    <!-- spring Container Monitor -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!--springMVC Core Distributor -->
    <servlet>
        <servlet-name>spring-mvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- Appoint Spring Configuration file -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <!-- Start loading once -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring-mvc</servlet-name>
        <!-- Here you can configure it to*.do Adaptation Struts Habit -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- Prevent Spring Memory overflow listener -->
    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>

    <!-- Solving Engineering Coding Filter -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

11.jsp/user.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>User</title>
</head>
<body>
    <h1>${requestScope.user}</h1>
</body>

12. Build a database test, and then create tables

CREATE TABLE `user` (
  `userid` INT(11) NOT NULL AUTO_INCREMENT,
  `username` VARCHAR(255) DEFAULT NULL,
  `password` VARCHAR(255) DEFAULT NULL,
  `email` VARCHAR(255) DEFAULT NULL,
  `phone` VARCHAR(255) DEFAULT NULL,
  `status` VARCHAR(255) NOT NULL DEFAULT '0',
  `code` VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (`userid`)
) ENGINE=INNODB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

13. Project deployment

Configure Tomcat access rights and tomcat-user.xml in Tomcat (Tomcat root directory / conf / Tomcat users. XML)

<role rolename="manager-gui"/> 
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user password="123456" username="root"
roles="manager-gui,manager-script,manager-jmx,manager-status" />

Double-click the startup.bat command in bin directory of Tomcat decompression package to start the Tomcat server. Access http://127.0.0.1:8080/manager in the browser address/

Enter the username root, password 123456 for login, if successful, please go to the next step.

Configure maven's set. XML
Add the following to the tag < servers > in the conf/set.xml file

 <server>
       <! - Let maven associate with our Tomcat server by tag name - >. 
        <id>tomcat8</id>
        <! - Username and password must be consistent with tomcat_user.xml in Tomcat - >
        <username>root</username>
        <password>123456</password>
    </server>

Add the following to the plugins child node of the pom.xml file

<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <url>http://127.0.0.1:8080/manager/text</url>
                    <!--Relation id-->
                    <server>tomcat8</server>
                    <username>root</username>
                    <password>123456</password>
                    <!--Access Path(Project name)-->
                    <path>/ssm01</path>
                    <update>true</update>
                </configuration>
            </plugin>

Run Tomcat directory / bin/startup.bat first
Then right-click the project Run As --- Maven build and enter: clean install tomcat7:redeploy in Goals

Visit the following diagram to show that the configuration was successful

Attachment: maven command
Executive order
1)Run as → clean install
2) Run as Tomcat 7: deploy note: first deployment execution
3) Run as Tomcat 7: redeploy note: second or later need to be reissued for execution
4) Run as tomcat 7: run note: deploy to tomcat to start

Errors encountered in the process

Start tomcat, compile and build

When using Mybatis to operate the underlying database, we need to use the xml configuration file. Usually we put the configuration file and Dao in the same directory. When working on a maven project, we may encounter a failure to read the mapper.xml file corresponding to dao. Add the following to the build node of pom.xml

<resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
</resources>

Keywords: Spring Maven xml Java

Added by foreverdita on Sat, 21 Sep 2019 18:16:01 +0300