开发工具
idea打开多微服务面板(workspace.xml)
<component name="RunDashboard">
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
github提交一个项目
1.github提交一个项目
(1)github添加新仓库jucdemo2
(2)添加客户端id_ras.pub秘钥(C:\Users\Czz\.ssh\id_ras.pub)
(3)添加远程仓库:
# 初始化本地仓库,并提交到本地仓库
$ cd D:\ideawk\jucdemo
$ git init
$ git add .
$ git commit -m 'first commit'
# 关联远程仓库并推送项目
$ git remote add origin git@github.com:line007/jucdemo2.git
# 第一次推送
$ git push -u origin master
# 非第一次推送
$ git push origin master
2.git checkout远程分支、标签
命令:git clone --branch [tags标签] [git地址] 或者 git clone --b [tags标签] [git地址]
例如:git clone -b 1.4.1 https://github.com/jumpserver/coco.git
git clone -b v6.3.0 https://github.com/theme-next/hexo-theme-next themes/next6.3
idea-pom项目无法识别
File->Settings->Build,Excecution,Deployment->Build Tools->Maven->Ignored Files
查看是否存在maven pom被勾选,去掉勾选即可。
linux
1.常用命令
-- 查看异常
$ tail -n 400 /usr/local/xx/logs/app-demo/error.log
-- 查看端口
$ netstat -tunlp
$ ps -aux | grep 668
-- 查看前10个最大的文件
$ du -a / | sort -nr | head -n 10
$ nohup java -jar xxl-job-admin.jar &
$ nohup java -jar xxl-job-executor-sample.jar &
2.nginx常用命令
$ nginx -t
$ ./nginx -s reload
3.redis常用命令
-- 查询删除KEY
$ key *
$ get menu_details::1_menu
$ del menu_details::1_menu
-- 清库
// 删除当前数据库中的所有Key
$ flushdb
// 删除所有数据库中的key
$ flushall
Spring
spring-auth2.0 自定义异常输出
参考网址

// 核心原理:定义WebResponseExceptionTranslator一个实现类,并将自定义异常处理类添加到认证服务器配置
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private WebResponseExceptionTranslator webResponseExceptionTranslator;
/** 用来配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services) */
@Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
...
endpoints.exceptionTranslator(webResponseExceptionTranslator);
...
}
...
}
// 1.定义继承OAuth2Exception的异常类
@JsonSerialize(using = PigAuth2ExceptionSerializer.class)
public class PigAuth2Exception extends OAuth2Exception {
@Getter
private String errorCode;
public PigAuth2Exception(String msg) {
super(msg);
}
public PigAuth2Exception(String msg, String errorCode) {
super(msg);
this.errorCode = errorCode;
}
}
// 2.定义序列化实现类
public class PigAuth2ExceptionSerializer extends StdSerializer<PigAuth2Exception> {
public PigAuth2ExceptionSerializer() {
super(PigAuth2Exception.class);
}
@Override
@SneakyThrows
public void serialize(PigAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
gen.writeStartObject();
gen.writeObjectField("code", CommonConstants.FAIL);
gen.writeStringField("msg", value.getMessage());
gen.writeStringField("data", value.getErrorCode());
gen.writeEndObject();
}
}
// 3.自定义实现异常转换类
/**
* @author lengleng
* @date 2019/2/1
* 异常处理,重写oauth 默认实现
*/
@Slf4j
public class PigWebResponseExceptionTranslator implements WebResponseExceptionTranslator {
private ThrowableAnalyzer throwableAnalyzer = new DefaultThrowableAnalyzer();
@Override
@SneakyThrows
public ResponseEntity<OAuth2Exception> translate(Exception e) {
// Try to extract a SpringSecurityException from the stacktrace
Throwable[] causeChain = throwableAnalyzer.determineCauseChain(e);
Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class,
causeChain);
if (ase != null) {
return handleOAuth2Exception(new UnauthorizedException(e.getMessage(), e));
}
ase = (AccessDeniedException) throwableAnalyzer
.getFirstThrowableOfType(AccessDeniedException.class, causeChain);
if (ase != null) {
return handleOAuth2Exception(new ForbiddenException(ase.getMessage(), ase));
}
ase = (InvalidGrantException) throwableAnalyzer
.getFirstThrowableOfType(InvalidGrantException.class, causeChain);
if (ase != null) {
return handleOAuth2Exception(new InvalidException(ase.getMessage(), ase));
}
ase = (HttpRequestMethodNotSupportedException) throwableAnalyzer
.getFirstThrowableOfType(HttpRequestMethodNotSupportedException.class, causeChain);
if (ase != null) {
return handleOAuth2Exception(new MethodNotAllowed(ase.getMessage(), ase));
}
ase = (OAuth2Exception) throwableAnalyzer.getFirstThrowableOfType(
OAuth2Exception.class, causeChain);
if (ase != null) {
return handleOAuth2Exception((OAuth2Exception) ase);
}
return handleOAuth2Exception(new ServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), e));
}
private ResponseEntity<OAuth2Exception> handleOAuth2Exception(OAuth2Exception e) {
int status = e.getHttpErrorCode();
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.CACHE_CONTROL, "no-store");
headers.set(HttpHeaders.PRAGMA, "no-cache");
if (status == HttpStatus.UNAUTHORIZED.value() || (e instanceof InsufficientScopeException)) {
headers.set(HttpHeaders.WWW_AUTHENTICATE, String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
}
// 客户端异常直接返回客户端,不然无法解析
if (e instanceof ClientAuthenticationException) {
return new ResponseEntity<>(e, headers,
HttpStatus.valueOf(status));
}
return new ResponseEntity<>(new PigAuth2Exception(e.getMessage(), e.getOAuth2ErrorCode()), headers,
HttpStatus.valueOf(status));
}
}
4.将自定义异常处理类添加到认证服务器配置
View Code