一 、eclipse安装springboot插件。 1.环境:eclipse,jdk1.8,tomcat8 在菜单栏中选择help-Eclipse marketplace ,在弹出窗口选择popular,找到Spring Tools,安装。
2.检查springboot插件是否成功安装。 Window-Show View --other,如下,出现spring则代表安装成功。
二、创建springboot项目 1.File-New-Spring Starter Project
2.选择各项目,如果要导出war包,则Packaging选War,
3.next,选择springboot 版本,要引入的组件,我引入了mybatis,mysql,web。完成。
4.创建完成,看一下目录结构。可以看到spring的启动类和另一个类ServletInitializer,他的作用是类似于web.xml的配置方式来启动spring上下文。
5.看一下java build path
6.在目录中加上mybaits的mapper映射
7.application.properties的内容看一下,若需要把项目部署到tomcat里并在浏览器访问,则需要设置server.servlet.context-path=/
- #\u8BBE\u7F6ETomcat\u7AEF\u53E3\uFF0C\u9ED8\u8BA48080
- server.port=8080
- #\u8BBE\u7F6E\u9879\u76EEContextPath
- server.servlet.context-path=/
- #\u8BBE\u7F6ETomcat\u7F16\u7801
- server.tomcat.uri-encoding=UTF-8
- #\u8BBE\u7F6E\u89C6\u56FE\u89E3\u6790\u5668\u8DEF\u5F84
- spring.mvc.view.prefix=/WEB-INF/views/
- #\u8BBE\u7F6E\u89C6\u56FE\u89E3\u6790\u5668\u540E\u7F00
- spring.mvc.view.suffix=.jsp
-
- #\u6570\u636E\u5E93\u914D\u7F6E
- spring.datasource.url=jdbc:mysql://localhost:3306/85paipai?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
- spring.datasource.username=root
- spring.datasource.password=root
- spring.datasource.driver-class-name=com.mysql.jdbc.Driver
-
- #\u914D\u7F6E.xml\u6587\u4EF6\u8DEF\u5F84
- mybatis.mapper-locations=classpath:mapper/*.xml
- #\u914D\u7F6E\u6A21\u578B\u8DEF\u5F84
- #mybatis.type-aliases-package=com.imgServer.domain
复制代码
8.看一下pom.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.example</groupId>
- <artifactId>springDemo-1</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <name>springDemo-1</name>
- <description>Demo project for Spring Boot</description>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.0.4.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.3.2</version>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <scope>runtime</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <finalName>demo</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
- </project>
复制代码
9.启动springboot 运行SpringDemo1Application.java 为main函数。
10.导出war包, 导出war包之前,项目右键Run 选择Maven-clean, 然后项目右键Maven -updata project ,当项目更新完之后,build path中的jdk会换成eclipse自带的javaSe-1.8,把它换成自己安装的jdk1.8,最后项目右键Run As ,选择Maven build
10.Goals 写package,勾选Skip Tests,点击Run
11.将war包放入tomcat 的webapp下,启动tomcat.浏览器输入http://localhost:8080/demo/hello,其中demo是在pom.xml中设置的,设置好finalName后,导出的war包名称即为demo.war。访问路径:http://localhost:8080/war包名/hello
|