Spring Boot项目实战(一)创建Maven项目搭建环境(Eclipse Jee)

1、创建maven项目;

2、选择 -webapp,输入项目包名,项目名;

3、报错就看看tomcat library有没有,没有就自己添加(add Library -- Server RunTime);

4、查看web.xml版本是2.3还是3.0,2.3就改为3.0,例如:

<?xml version="1.0" encoding="UTF-8"?>  
<web-app version="3.0"  
    xmlns="http://java.sun.com/xml/ns/javaee"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"/>


5、项目右键,点击show in --> System Explorer,在文件夹中打开项目,进入.setting文件夹,最好用notepad++打开 org.eclipse.wst.common.project.facet.core.xml文件,修改成如下并保存:

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="wst.jsdt.web"/>
  <installed facet="java" version="1.8"/>
  <installed facet="jst.web" version="3.0"/>
  <installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

6、打开pom.xml,添加springboot相关jar包:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
  
  <dependencies>
  
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            
             <!-- 去除内嵌tomcat -->
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
      </exclusions>         
    </dependency>
        
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
  
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
    
     <!-- servlet依赖. -->
        <dependency>
              <groupId>javax.servlet</groupId>
              <artifactId>javax.servlet-api</artifactId>
        </dependency>
        
         <!-- jstl -->
              <dependency>
                     <groupId>javax.servlet</groupId>
                     <artifactId>jstl</artifactId>
              </dependency>
              
     <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
              
         
          
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
        </dependency>
        
       <!-- mysql -->
        <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>8.0.15</version><!--$NO-MVN-MAN-VER$-->
    </dependency>
    
    <!-- mybatis -->
     <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.1.1</version>
    </dependency>
    
     <!-- pagehelper -->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>4.1.6</version>
        </dependency>
    
  </dependencies>
  
  <properties>
        <java.version>1.8</java.version>
    </properties>
  
  <build>
    <finalName>springboot-project</finalName>
    
    <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            
             <!-- 编译的时候使用JDK8和UTF8编码 ,-->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- <version>3.0</version> -->
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            
            <plugin>
        <artifactId>maven-war-plugin</artifactId>
      </plugin>
            
    </plugins>
    
  </build>

7、左下角jar包加载完后,右键项目 Maven -->  Update Project。

8、Maven项目搭建完成。

发布了22 篇原创文章 · 获赞 6 · 访问量 4885

猜你喜欢

转载自blog.csdn.net/qq_37651252/article/details/97416930