快速开始
从0开始创建一个基于hsweb的项目。在本文档中,使用的开发环境为IntelliJ IDEA ,需安装lombok插件

创建项目

编辑pom.xml

如果对maven不够熟悉,maven的设置请使用默认设置,不要在settings.xml里自己添加私服. 否则可能出现依赖无法下载的问题。 编辑后请reimport maven。
pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
<modelVersion>4.0.0</modelVersion>
6
7
<groupId>com.mycompany</groupId>
8
<artifactId>myproject</artifactId>
9
<version>1.0-SNAPSHOT</version>
10
<properties>
11
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12
<project.build.locales>zh_CN</project.build.locales>
13
<spring.boot.version>1.5.13.RELEASE</spring.boot.version>
14
15
<java.version>1.8</java.version>
16
<project.build.jdk>${java.version}</project.build.jdk>
17
<!--hsweb版本-->
18
<hsweb.framework.version>3.0.6</hsweb.framework.version>
19
</properties>
20
21
<build>
22
<finalName>${project.artifactId}</finalName>
23
<resources>
24
<resource>
25
<directory>src/main/resources</directory>
26
<filtering>true</filtering>
27
</resource>
28
</resources>
29
<plugins>
30
<!--编译插件-->
31
<plugin>
32
<groupId>org.apache.maven.plugins</groupId>
33
<artifactId>maven-compiler-plugin</artifactId>
34
<version>3.1</version>
35
<!--指定编译器版本和字符集-->
36
<configuration>
37
<source>${project.build.jdk}</source>
38
<target>${project.build.jdk}</target>
39
<encoding>${project.build.sourceEncoding}</encoding>
40
</configuration>
41
</plugin>
42
43
<!--
44
spring-boot插件
45
1. 可以使用命令 mvn spring-boot:run 直接运行项目
46
2. 使用mvn package命令打包为可执行jar,通过jar -jar 运行项目
47
-->
48
<plugin>
49
<groupId>org.springframework.boot</groupId>
50
<artifactId>spring-boot-maven-plugin</artifactId>
51
<version>${spring.boot.version}</version>
52
<configuration>
53
<!--启动类-->
54
<mainClass>com.mycompany.MyProjectApplication</mainClass>
55
<layout>ZIP</layout>
56
</configuration>
57
<executions>
58
<execution>
59
<goals>
60
<goal>repackage</goal>
61
</goals>
62
</execution>
63
</executions>
64
</plugin>
65
66
</plugins>
67
</build>
68
69
<dependencies>
70
71
<!--test-->
72
<dependency>
73
<groupId>org.springframework.boot</groupId>
74
<artifactId>spring-boot-starter-test</artifactId>
75
<scope>test</scope>
76
</dependency>
77
<dependency>
78
<groupId>org.hswebframework.web</groupId>
79
<artifactId>hsweb-tests</artifactId>
80
<version>${hsweb.framework.version}</version>
81
<scope>test</scope>
82
</dependency>
83
84
<!--必须要引入的依赖-->
85
<!--对spring-cache一些问题的修复-->
86
<dependency>
87
<groupId>org.hswebframework.web</groupId>
88
<artifactId>hsweb-concurrent-cache</artifactId>
89
<version>${hsweb.framework.version}</version>
90
</dependency>
91
92
<!--spring-boot-starter-->
93
<dependency>
94
<groupId>org.hswebframework.web</groupId>
95
<artifactId>hsweb-spring-boot-starter</artifactId>
96
</dependency>
97
98
<dependency>
99
<groupId>org.springframework.boot</groupId>
100
<artifactId>spring-boot-starter-logging</artifactId>
101
</dependency>
102
103
<dependency>
104
<groupId>org.codehaus.groovy</groupId>
105
<artifactId>groovy-all</artifactId>
106
</dependency>
107
108
<dependency>
109
<groupId>mysql</groupId>
110
<artifactId>mysql-connector-java</artifactId>
111
<version>5.1.40</version>
112
</dependency>
113
114
<dependency>
115
<groupId>com.alibaba</groupId>
116
<artifactId>druid</artifactId>
117
</dependency>
118
119
<dependency>
120
<groupId>ch.qos.logback</groupId>
121
<artifactId>logback-classic</artifactId>
122
</dependency>
123
124
<dependency>
125
<groupId>org.slf4j</groupId>
126
<artifactId>slf4j-api</artifactId>
127
</dependency>
128
129
<dependency>
130
<groupId>org.springframework.boot</groupId>
131
<artifactId>spring-boot-configuration-processor</artifactId>
132
<optional>true</optional>
133
</dependency>
134
135
<dependency>
136
<groupId>org.projectlombok</groupId>
137
<artifactId>lombok</artifactId>
138
</dependency>
139
140
<!--以下为可选依赖,新增模块时,往这添加-->
141
142
143
</dependencies>
144
145
<!--统一依赖管理-->
146
<dependencyManagement>
147
<dependencies>
148
<dependency>
149
<groupId>org.hswebframework.web</groupId>
150
<artifactId>hsweb-framework</artifactId>
151
<version>${hsweb.framework.version}</version>
152
<type>pom</type>
153
<scope>import</scope>
154
</dependency>
155
156
<dependency>
157
<groupId>com.alibaba</groupId>
158
<artifactId>druid</artifactId>
159
<version>1.0.26</version>
160
</dependency>
161
162
<dependency>
163
<groupId>org.hswebframework.web</groupId>
164
<artifactId>hsweb-spring-boot-starter</artifactId>
165
<version>${hsweb.framework.version}</version>
166
</dependency>
167
168
</dependencies>
169
170
</dependencyManagement>
171
<!--pom里引入私服,无需再到 settings.xml中配置-->
172
<repositories>
173
<repository>
174
<id>hsweb-nexus</id>
175
<name>Nexus Release Repository</name>
176
<url>http://nexus.hsweb.me/content/groups/public/</url>
177
<snapshots>
178
<enabled>true</enabled>
179
<updatePolicy>always</updatePolicy>
180
</snapshots>
181
</repository>
182
<repository>
183
<id>aliyun-nexus</id>
184
<name>aliyun</name>
185
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
186
</repository>
187
</repositories>
188
189
<pluginRepositories>
190
<pluginRepository>
191
<id>aliyun-nexus</id>
192
<name>aliyun</name>
193
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
194
</pluginRepository>
195
</pluginRepositories>
196
197
</project>
Copied!

创建配置文件

resources目录中创建application.yml配置文件
resources/application.yml
1
server:
2
port: 8080
3
spring:
4
aop:
5
auto: true
6
datasource:
7
type: com.alibaba.druid.pool.DruidDataSource
8
driver-class-name : com.mysql.jdbc.Driver
9
url : jdbc:mysql://localhost:3306/myproject?useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
10
username : root
11
password : root
12
13
hsweb:
14
app:
15
name: my-project
16
version: 1.0.0
17
18
logging:
19
level:
20
org.hswebframework.web: DEBUG
21
org.hswebframework.web.cache: WARN
22
org.apache.ibatis: DEBUG
23
org.mybatis: DEBUG
Copied!

创建启动类

MyProjectApplication.java
1
package com.mycompany;
2
3
import org.springframework.boot.SpringApplication;
4
import org.springframework.boot.autoconfigure.SpringBootApplication;
5
6
/**
7
* @author zhouhao
8
* @since 1.0
9
*/
10
@SpringBootApplication
11
public class MyProjectApplication {
12
13
public static void main(String[] args) {
14
SpringApplication.run(MyProjectApplication.class,args);
15
}
16
}
Copied!

创建数据库

此处使用mysql数据库, 可根据需要选择合适的数据库. 支持 H2 Mysql Oracle PostgreSQL
1
CREATE DATABASE IF NOT EXISTS myproject default charset utf8 COLLATE utf8_general_ci;
Copied!

启动服务

打开浏览器访问 http://localhost:8080. 提示Whitelabel Error Page则说明服务启动成功. 因为现在还没有任何功能,所有提示错误信息.到此,项目建立完成,和普通的spring-boot项目没有区别.
Last modified 3yr ago