原文:Spring 团队(无个人署名),Securing a Web Application。本文依据 2026 年 10 月 5 日读取的完整指南翻译整理,保留 Java、Kotlin 及 Gradle、Maven 两套示例。代码按 Apache License 2.0 发布,原指南文字采用 CC BY-ND 3.0;Copyright © 2005–2026 Broadcom。
这篇指南从一个任何人都能打开的 Spring MVC 网站开始,为问候页加入登录要求。完成后,首页仍可匿名访问,访问受保护页面时会先进入登录表单,登录成功后回到原先要访问的页面。用户信息暂存在内存中,目的是把认证过程讲清楚。

准备项目,并先确认版本
原指南预计约 15 分钟,需要编辑器或 IDE、Java 17 或更高版本,以及 Gradle 或 Maven。可以使用 Spring Tool Suite、IntelliJ IDEA 或 VS Code。可以从零开始,也可以下载或克隆 示例仓库,进入 gs-securing-web/initial,直接从下一节做起;完成后与 complete 目录比较。
git clone https://github.com/spring-guides/gs-securing-web.git
cd gs-securing-web/initial
版本核对:源页页首仍写 Gradle 7.5+、Maven 3.5+,但当前 Java 构建示例已经使用 Spring Boot 4.0.8,Kotlin 示例为 4.0.0。这些数字不是一套已经统一验证的配置。不要把旧页首要求与 Boot 4 配置混用;应采用所选项目的 wrapper,并核对对应版本的系统要求。核验当日的 Spring Boot 当前系统要求页面是 4.1.1,列出 Maven 3.6.3+、Gradle 8.14+ 的 8.x 或 9.x;这只是核对线索,不能替代目标 4.0.x 的版本说明。下面保留源页代码版本,未执行构建。
从零创建时,打开 Spring Initializr,选择构建工具和语言,加入 Spring Web 与 Thymeleaf,点击 Generate,下载并解压项目。支持 Initializr 的 IDE 也可以直接完成这一步;熟悉 GitHub 的读者可以 fork 示例仓库,再用本地编辑器打开。
先建立不需要认证的页面
首页模板保存为 src/main/resources/templates/home.html。其中的 Thymeleaf 链接会指向 /hello。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
<title>Spring Security Example</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Click <a th:href="@{/hello}">here</a> to see a greeting.</p>
</body>
</html>
问候页保存为 src/main/resources/templates/hello.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
Spring MVC 还需要把 URL 路径映射到模板。在 com.example.securingweb 包中创建 MvcConfig,实现 WebMvcConfigurer 并覆盖 addViewControllers()。下面分别是 Java 和 Kotlin 写法,实际项目只选与项目语言对应的一套。
package com.example.securingweb;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
class MvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
}
package com.example.securingweb
import org.springframework.context.annotation.Configuration
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
@Configuration
class MvcConfig : WebMvcConfigurer {
override fun addViewControllers(registry: ViewControllerRegistry) {
registry.addViewController("/home").setViewName("home")
registry.addViewController("/").setViewName("home")
registry.addViewController("/hello").setViewName("hello")
registry.addViewController("/login").setViewName("login")
}
}
/ 和 /home 都使用 home 视图;/hello 使用 hello;/login 使用下一节将创建的 login 视图。此时尚未加入安全限制,访问问候页不需要登录。
加入 Spring Security 依赖
希望只有认证过的用户可以看到 /hello,就需要把 Spring Security 加入 classpath,并配置认证规则。Spring Boot 会为检测到的安全依赖提供默认安全配置;下面通过自己的过滤器链明确使用表单登录,而不依赖默认行为。Thymeleaf 的安全扩展用于显示当前用户名,安全测试依赖为后续编写测试提供支持。
Gradle Groovy 配置添加:
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.security:spring-security-test'
Gradle Kotlin DSL 配置添加:
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6")
testImplementation("org.springframework.boot:spring-boot-starter-security-test")
源文给出的完整 build.gradle 如下。其中测试依赖同时列出 spring-security-test 与 Boot 安全测试 starter;这是源文现状,不代表需要手工重复加入所有依赖。
plugins {
id 'java'
id 'org.springframework.boot' version '4.0.8'
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
}
test {
useJUnitPlatform()
}
以下是源文的完整 build.gradle.kts,其中还包含 Kotlin 插件、反射库和编译器参数:
plugins {
id("org.springframework.boot") version "4.0.0"
id("io.spring.dependency-management") version "1.1.7"
kotlin("jvm") version "2.2.21"
kotlin("plugin.spring") version "2.2.21"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-webmvc")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6")
testImplementation("org.springframework.boot:spring-boot-starter-security-test")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
}
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict", "-Xannotation-default-target=param-property")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
使用 Maven 时,在 pom.xml 的 dependencies 下加入安全 starter、Thymeleaf 安全扩展和测试 starter。原文此处称“两项”,实际代码列出三项,本文按代码说明。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-test</artifactId>
<scope>test</scope>
</dependency>
完整 Maven 配置:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>4.0.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>securing-web-complete</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
定义路径规则、密码编码器和内存用户
WebSecurityConfig 配置类打开 Web 安全支持,并提供过滤器链、密码编码器和用户查询服务。原文描述曾写“两个 bean”,当前示例实际包含三个。
package com.example.securingweb;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
class WebSecurityConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) {
// @formatter:off
http
.authorizeHttpRequests((requests) -> requests
.requestMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
)
.formLogin((form) -> form
.loginPage("/login")
.permitAll()
)
.logout(LogoutConfigurer::permitAll);
// @formatter:on
return http.build();
}
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
UserDetailsService userDetailsService(PasswordEncoder encoder) {
String password = encoder.encode("password");
UserDetails user = User.withUsername("user").password(password).roles("USER").build();
return new InMemoryUserDetailsManager(user);
}
}
Kotlin 版本使用 Spring Security Kotlin DSL。它在用户服务内部重新创建 BCrypt 编码器,而 Java 版本注入已经声明的 PasswordEncoder;本文保留这一原文差异。
package com.example.securingweb
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.annotation.web.invoke
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.security.web.SecurityFilterChain
@Configuration
@EnableWebSecurity
class WebSecurityConfig {
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
// Kotlin security extensions allow concise DSL instead of builder-style lambdas
authorizeHttpRequests {
authorize("/", permitAll)
authorize("/home", permitAll)
authorize(anyRequest, authenticated)
}
formLogin {
loginPage = "/login"
permitAll()
}
logout {
permitAll()
}
}
return http.build()
}
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
@Bean
fun userDetailsService(): UserDetailsService {
val encoder = BCryptPasswordEncoder()
val user = User.builder()
.username("user")
.password(encoder.encode("password"))
.roles("USER")
.build()
return InMemoryUserDetailsManager(user)
}
}
SecurityFilterChain 将 / 与 /home 设为 permitAll(),其他请求要求 authenticated()。formLogin() 指定自定义登录页 /login,并允许未登录用户访问登录流程;退出登录也允许访问。登录成功后,安全框架通常把用户带回先前请求的受保护地址。
UserDetailsService 返回一个 InMemoryUserDetailsManager。示例用户的用户名是 user,密码是 password,角色为 USER;密码交给 BCrypt 编码后再存入内存用户对象。
安全边界:这个固定的弱密码是公开教学凭据,不是泄露的真实密钥。即使使用 BCrypt,也不能把 user/password 带入对外系统。内存账户没有持久化注册、重置密码、账号禁用或多因素认证能力。生产项目必须另行设计账户存储、权限粒度、速率限制、会话寿命及 HTTPS;这篇指南并未提供这些能力。不要为了让演示“能用”而关闭 CSRF 保护。
编写登录与退出表单
在 src/main/resources/templates/login.html 中放入以下模板。用户名和密码输入框的 name 分别是 username、password,表单通过 POST 提交到 /login。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org">
<head>
<title>Spring Security Example </title>
</head>
<body>
<div th:if="${param.error}">
Invalid username and password.
</div>
<div th:if="${param.logout}">
You have been logged out.
</div>
<form th:action="@{/login}" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
</body>
</html>
登录请求由 Spring Security 的过滤器拦截并认证,无须自己为登录提交再写 MVC 控制器。认证失败时返回 /login?error,模板据此显示错误;成功退出后返回 /login?logout,显示退出提示。采用 Thymeleaf 与 Spring Security 正确集成的表单时,应保留框架生成的 CSRF 令牌;不能把示例直接改成无令牌的裸 HTML 提交。
更新 hello.html,通过 sec:authentication="name" 读取当前认证用户的名字,并增加 POST 到 /logout 的退出表单。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
<head>
<title>Hello World!</title>
</head>
<body>
<h1 th:inline="text">Hello <span th:remove="tag" sec:authentication="name">thymeleaf</span>!</h1>
<form th:action="@{/logout}" method="post">
<input type="submit" value="Sign Out"/>
</form>
</body>
</html>
这里使用模板引擎的标准文本输出,不把用户名拼接为任意 HTML。退出操作结束后,用户会回到登录页;此时再次访问受保护页面,应重新认证。
启动应用与核对完整流程
Initializr 已生成应用入口,这里不需要额外修改。Java 入口如下:
package com.example.securingweb;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
class SecuringWebApplication {
public static void main(String[] args) {
SpringApplication.run(SecuringWebApplication.class, args);
}
}
Kotlin 入口如下:
package com.example.securingweb
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class SecuringWebApplication
fun main(args: Array<String>) {
runApplication<SecuringWebApplication>(*args)
}
Gradle 项目可以使用 ./gradlew bootRun 启动,或先执行 ./gradlew build,再运行打包出的 JAR。原文示例命令为:
java -jar build/libs/gs-securing-web-0.0.1-SNAPSHOT.jar
Maven 项目可以使用 ./mvnw spring-boot:run;或者执行 ./mvnw clean package 后运行:
java -jar target/gs-securing-web-0.0.1-SNAPSHOT.jar
命令核对:原 Maven 的 artifactId 为 securing-web-complete,而上述命令使用 gs-securing-web,实际文件名必须以生成的 target 或 build/libs 目录为准。Windows 使用相应的 mvnw.cmd 或 gradlew.bat。clean 会清理本项目构建输出;wrapper 及构建插件可能下载依赖并执行构建逻辑,只应对已审查的项目运行。本文未运行这些命令。
在你自己的隔离开发环境启动后,打开 http://localhost:8080。预期先看到首页;点击问候页链接时,未认证会进入登录页。输入演示凭据 user/password 后,应回到问候页并看到用户名。点击 Sign Out,应回到带退出提示的登录页。若直接进入问候页,检查是否还停留在“未加入安全配置”的阶段。还应核对错误密码路径、退出后重新访问以及表单令牌处理;这些是读者需要完成的验证步骤,本文不声称已经实测。
继续阅读
这套示例完整展示了公开首页、受保护资源、表单认证和退出之间的关系。继续扩展前,可阅读 Building an Application with Spring Boot、Serving Web Content with Spring MVC 以及原指南链接的 Spring Security and Angular JS 教程。指南贡献说明见 Spring Guides。
原始版权与许可
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.












暂无评论内容