problem terminator

常见bug

权限问题

  • rabbitmq-service.bat start 时一定要以管理员身份进入,不然会被拒绝
  • Spring Security的AccessDenied错误,检查一下数据库有没有给用户授权并且关联角色
  • Spring Security构建 SimpleGrantedAuthority 对象的时候,角色必须以 ROLE_开头。SimpleGrantedAuthority auth = new SimpleGrantedAuthority("ROLE_"+roleMapper.findById(role.getRoleId()).getRoleCode());

版本问题

  • Java版本问题
  • 版本:commons-codec 1.12 版本能正常解密微信的消息,升级为1.13后出现了不能正常decode
  • 版本:未指定版本:Cannot resolve org.springframework.boot:spring-boot-starter-data-redis:unknown

Git

Redis

Redis-cli命令

Redis配置文件

Redis内存相关

SpringBoot中使用Redis

PostgreSQL

导入导出

定时备份数据库

Linux之坑

新建用户

  1. 新增用户:useradd -m zhangsan
  2. 设置密码:passwd zhangsan
  3. 赋予用户sudo权限:vim /etc/sudoers(需要先chmod 640 sudoers,因为该文件本来是只读的)在root ALL=(ALL) ALL的下一行添加 : zhangsan ALL=(ALL) ALL貌似不能在文件末尾添加,会报错
  4. 别忘了chmod 440 sudoers

改坏sudoers文件

ll命令失效

  1. 运行 vi ~/.bashrc,查看该文件里是否有alias ll='ls -l' 这样的数据,如有,将数据前的 “#” 去掉,如果没有,将 alias ll='ls -l'加进去并保存,然后运行 source ~/.bashrc 命令,即可成功
  2. 如果只做完第一步,可能重新登录后ll命令还是失效,那就需要打开(如果没有的话先创建)文件: ~/.bash_profile 。 在里面加入一行:source ~/.bashrc

Ubuntu 18.04 装环境

RabbitMq

Consul

#!/bin/bash
/usr/local/bin/consul agent -dev
  • 执行命令:chmod 777 consul.sh
  • 然后在/lib/systemd/system目录下注册一个服务,配置如下:
[Unit]
Description=consul service
After=network.target
After=systemd-user-sessions.service
After=network-online.target

[Service]
User=root
Type=simple
WorkingDirectory=/root     #这个就是脚本所在的目录(实际配置时请删掉注释)
ExecStart=/root/consul.sh  #这个就是脚本(实际配置时请删掉注释)
TimeoutSec=30
Restart=on-failure
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=multi-user.target

Postgresql

Java11-Open-jdk

  • 一句搞定:apt-get install openjdk-11-jdk

Nginx

CentOS 7.3 各种安装

安装支持ZIP的工具

安装postgresql

  • 参考:https://cloud.tencent.com/developer/article/1592808
  • 上文只作为参考,实际安装时发现postgresql-setup这个文件并不在/usr目录下,而在/usr/bin目录下
  • 初始化成功并启动服务后执行su - postgres,然后执行psql,如果成功,就表示数据库安装成功了

安装Java

安装nginx

安装consul

  • 和上文Ubuntu安装consul步骤一样

CentOS 7.4 配置本地yum源

Windows部署Java服务

  1. Java项目打包成jar
  2. 服务注册,参考:https://blog.csdn.net/LMGD_/article/details/106144786
  3. 注册成功后,在jar所在目录执行:net start 服务名(可能需要以管理员权限执行)
  4. 运行services.msc,确认服务是否已启动

我的xml配置

<service>
    <id>rkeService</id>
    <name>rke Service</name>
	<description>a service</description>
    <executable>java</executable>
    <arguments>-jar rkeService.jar</arguments>
	<startmode>Automatic</startmode>
    <logmode>reset</logmode>
	<logpath>C:\Users\Lenovo\Desktop\server\logs</logpath>
</service>

其他参考:https://blog.csdn.net/bighuan/article/details/83416390如果已经成功就不用看了

Spring Security

关闭Spring Security的鉴权

适用于基于spring boot+spring security+jwt的项目

  1. 在springsecurity配置类上去掉@EnableGlobalMethodSecurity注解
  2. 在springsecurity配置类的如下方法中,添加.anyRequest().permitAll();
	@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
    
    
        httpSecurity
            .cors()//跨域资源请求开启
            .and()
            .csrf().disable() //不开启跨站请求伪造
            .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint)
                .accessDeniedHandler(new CustomAccessDeineHandler())
            .and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .authorizeRequests()//拦截请求,创建FilterSecurityInterceptor,该方法用于配置权限
            .antMatchers("/swagger-ui.html").permitAll()
            .antMatchers("/teacher/login").permitAll()
            .antMatchers("/visitor/login").permitAll()
//            .anyRequest().authenticated();
            .anyRequest().permitAll();
        httpSecurity.addFilterBefore(jwtAuthorizationTokenFilter, UsernamePasswordAuthenticationFilter.class);
    }

IntelliJ IDEA上调用WCF服务

IntelliJ IDEA连接服务器上的数据库

Postman

如何测试含有占位符的接口?

  • 接口:@DeleteMapping("/optionalcourse/{id}")
  • 测试方法如下(id前加冒号):
    在这里插入图片描述

常用开发组件

RestTemplate

Apache POI

参考:

正则表达式

上传图片到服务器指定路径

接收图片的代码参考:

public String uploadFile(MultipartFile file, String path) {
    
    
        if (file.isEmpty()){
    
    
            log.error("file is empty");
            return null;
        }
        String fileName = file.getOriginalFilename();
        if (fileName == null || "".equals(fileName.trim())) return null;
        log.debug("filename: " + fileName);
        String suffix = fileName.substring(fileName.lastIndexOf("."));
        log.debug("suffix: " + suffix);
        fileName = DateUtil.getTimeStamp() + "_" + fileName;
        log.debug("filename with timestamp: " + fileName);
        File imgFile = new File(path + fileName);
        if (!imgFile.getParentFile().exists()) {
    
    
            if (!imgFile.getParentFile().mkdirs()) {
    
     //注意mkdir()和mkdirs()区别
                log.error("mkdirs: " + imgFile.getParentFile() + "failed");
                return null;
            }
        }
        try {
    
    
            file.transferTo(imgFile);// 文件写入,必须使用绝对路径加文件名,且路径存在
        } catch (IOException e) {
    
    
            log.error(e.getMessage());
            return null;
        }
        return fileName;
    }

SpringBoot相关

@Valid

  • @Valid加在方法参数上的前提是必须在类上加@Validate才生效

参考文章:

搭建SpringBoot多模块项目

Spring Boot项目引入第三方jar包

SpringBoot配置自定义拦截器

配置https证书

Spring相关

Spring中的Bean

MybatisPlus

开发中遇到的其他问题

开发规范

Restful风格

Coding注意事项

  1. Reject perfectionism 拒绝完美主义
  2. Quick debug(need experience and patience)
  3. Pursue simplicity 追求简洁

猜你喜欢

转载自blog.csdn.net/rakish_wind/article/details/116175727