spring boot 编码问题?

一、返回数据中文乱码问题?

1、查看了项目的编码,发现没问题

2、在application.properties中设置了编码,还是不行

server:
  servlet:
    encoding:
      charset: UTF-8
      enabled: true
      force: true

3、回想是执行了mvn clean install 以后出现乱码的,应该是maven编译打包时没有指定编码,在项目根pom中加入编译打包配置,发现问题解决。

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

二、properties文件注释变为了unicode编码
  

把这里勾选上,如果还不行就自行转换一下吧

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot中启用Spring Security通常涉及以下几个步骤: 1. 添加依赖:首先,在你的`pom.xml`或`build.gradle`文件中添加Spring Security的相关依赖。例如,如果你使用Maven,你可以添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> ``` 2. 配置Web:在Spring Boot应用中,确保启用了Web模块。如果使用Java配置,可以在`Application`类上添加`@EnableWebSecurity`注解: ```java @SpringBootApplication @EnableWebSecurity public class Application { // ... } ``` 3. 定义Security Configuration:创建一个实现了`WebSecurityConfigurerAdapter`的类,这将用来配置你的安全规则和认证策略。例如,你可以覆盖`configure(HttpSecurity http)`方法: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user") .password(passwordEncoder().encode("password")) .roles("USER"); } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/public/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .defaultSuccessUrl("/") .permitAll(); } // ...其他配置,如密码编码器、会话管理等 } ``` 这里设置了简单的内存中的用户认证,后续可能需要连接到数据库或使用JWT等其他方式。 4. 创建登录页面(可选):如果你想提供一个自定义的登录页面,可以在资源目录下创建HTML文件,并配置`formLogin()`的`loginPage`属性指向这个页面。 5. 运行应用:启动Spring Boot应用,Spring Security将自动生效,根据你的配置拦截HTTP请求并处理认证。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值