SpringBoot项目application.properties文件无效的问题

SpringBoot项目application.properties文件无效的解决办法

1、第一

1.在设置里面这样打开,去掉打钩的
在这里插入图片描述

  1. 第二步是,在对应的模块这样设置

在这里插入图片描述

  1. 然后继续设置

在这里插入图片描述

2、第二

  1. 创建启动类
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.5.4</version>
        </dependency>
package org.example;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class adminApplication {

    public static void main(String[] args) {

        SpringApplication.run(adminApplication.class,args);
    }
}

  1. 差不就行了
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot中使用spring.redis.database属性时无效可能是因为以下原因: 1. 检查配置文件:首先,请确保你的配置文件(例如application.propertiesapplication.yml)中正确地设置了spring.redis.database属性。确保在正确的位置设置了正确的数据库编号。如果在配置文件中设置了其他Redis属性,也请确保没有冲突或被覆盖。 2. Redis版本兼容性:如果你使用的是较旧的Redis版本,可能会导致该属性无效。确保你的Redis版本与Spring Boot版本兼容,并且支持使用该属性进行数据库选择。 3. Bean配置:在Spring Boot中,Redis连接是通过RedisConnectionFactory和RedisTemplate进行管理的。请确保你已正确配置这些Bean,并将其与spring.redis.database属性关联起来。例如,可以使用以下配置创建一个RedisTemplate Bean: ``` @Configuration public class RedisConfig { @Value("${spring.redis.database}") private int database; @Autowired private RedisConnectionFactory connectionFactory; @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(connectionFactory); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); template.setEnableTransactionSupport(true); template.setEnableDefaultSerializer(true); template.afterPropertiesSet(); return template; } } ``` 请确保在配置类中注入了spring.redis.database属性,并将其应用于RedisTemplate。这将确保Redis连接将选择正确的数据库。 如果上述解决方案仍然无效,可能需要进行更详细的排查,例如检查Redis服务器状态,确认配置是否正确等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值