Skip to content

Commit 96460ff

Browse files
committed
feat: login and password
1 parent f519407 commit 96460ff

File tree

6 files changed

+127
-8
lines changed

6 files changed

+127
-8
lines changed

readme.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,46 @@ cd view-redis
1616
mvn clean install
1717
```
1818

19-
```xml
20-
<dependency>
21-
<groupId>com.github.huifer</groupId>
22-
<artifactId>view-redis-boot</artifactId>
23-
<version>last-version</version>
24-
</dependency>
2519

26-
```
2720

2821
## Using
22+
### 第一种
23+
- 引入依赖
24+
25+
```xml
26+
<dependency>
27+
<groupId>com.github.huifer</groupId>
28+
<artifactId>view-redis-boot</artifactId>
29+
<version>1.0-SNAPSHOT</version>
30+
</dependency>
31+
```
2932

3033
- 在启动类上增加注解`@EnableViewRedis`
3134
- 如果有拦截器请将`/redis/**/`作为忽略,不执行拦截器逻辑
3235
- 访问 `/redis/index` 进入管理页面
3336

37+
### 第二种
38+
- 引入依赖
39+
40+
```xml
41+
<dependency>
42+
<groupId>com.github.huifer</groupId>
43+
<artifactId>view-redis-servlet</artifactId>
44+
<version>1.0-SNAPSHOT</version>
45+
</dependency>
46+
47+
```
48+
49+
- 在启动类上添加`@EnableViewRedisServlet`
50+
- 设置账号密码, 默认账号密码: **redis-admin\redis-admin**
51+
```
52+
view:
53+
redis:
54+
login_name: admin
55+
password: admin
56+
```
57+
58+
3459

3560
## 系统截图
3661
- redis 配置相关截图

sample/servlet-sample/src/main/resources/application.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ spring:
88
host: 127.0.0.1
99
port: 6379
1010

11+
12+
1113
logging:
1214
level:
13-
com.github.huifer.view.redis: debug
15+
com.github.huifer.view.redis: debug
16+
17+
18+
view:
19+
redis:
20+
login_name: admin
21+
password: admin

view-redis-servlet/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
<groupId>com.google.code.gson</groupId>
2929
<artifactId>gson</artifactId>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-configuration-processor</artifactId>
34+
<optional>true</optional>
35+
</dependency>
3136
</dependencies>
3237
</project>

view-redis-servlet/src/main/java/com/github/huifer/view/redis/servlet/Beans.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
package com.github.huifer.view.redis.servlet;
22

33
import java.util.Collections;
4+
import java.util.HashMap;
5+
import java.util.Map;
46

57
import javax.servlet.Servlet;
68

9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
711
import org.springframework.boot.web.servlet.ServletRegistrationBean;
12+
import org.springframework.context.ApplicationContext;
813
import org.springframework.context.annotation.Bean;
914
import org.springframework.context.annotation.ComponentScan;
1015
import org.springframework.stereotype.Component;
1116

17+
import static com.github.huifer.view.redis.servlet.ViewRedisServlet.LOGIN_NAME_PARAM;
18+
import static com.github.huifer.view.redis.servlet.ViewRedisServlet.PASSWORD_PARAM;
19+
1220
@Component
1321
@ComponentScan("com.github.huifer.view.redis.*")
22+
@EnableConfigurationProperties(ViewRedisConfig.class)
1423
public class Beans {
1524

25+
@Autowired
26+
private ApplicationContext context;
1627

1728
@Bean
1829
public ServletRegistrationBean statViewServletRegistrationBean() {
1930
ServletRegistrationBean<Servlet> servletServletRegistrationBean = new ServletRegistrationBean<>();
2031
servletServletRegistrationBean.setServlet(new ViewRedisServlet("/support/"));
32+
Map<String, String> initParams = new HashMap<>(10);
33+
ViewRedisConfig bean = context.getBean(ViewRedisConfig.class);
34+
35+
36+
if (bean != null) {
37+
38+
initParams.put(LOGIN_NAME_PARAM, bean.getLoginName());
39+
initParams.put(PASSWORD_PARAM, bean.getPassword());
40+
41+
}
42+
servletServletRegistrationBean.setInitParameters(initParams);
2143
servletServletRegistrationBean.setUrlMappings(Collections.singleton("/redis/*"));
2244
return servletServletRegistrationBean;
2345
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright 2020 HuiFer All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.github.huifer.view.redis.servlet;
20+
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
23+
@ConfigurationProperties(prefix = "view.redis")
24+
public class ViewRedisConfig {
25+
private String loginName;
26+
27+
private String password;
28+
29+
public String getLoginName() {
30+
return loginName;
31+
}
32+
33+
public void setLoginName(String loginName) {
34+
this.loginName = loginName;
35+
}
36+
37+
public String getPassword() {
38+
return password;
39+
}
40+
41+
public void setPassword(String password) {
42+
this.password = password;
43+
}
44+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"properties": [
3+
{
4+
"name": "view.redis.login_name",
5+
"type": "java.lang.String",
6+
"sourceType": "com.github.huifer.view.redis.servlet.ViewRedisConfig"
7+
},
8+
{
9+
"name": "view.redis.password",
10+
"type": "java.lang.String",
11+
"sourceType": "com.github.huifer.view.redis.servlet.ViewRedisConfig"
12+
}
13+
]
14+
15+
}

0 commit comments

Comments
 (0)