首页 > 解决方案 > WebServerException:无法启动嵌入式 Tomcat

问题描述

我想调试我的 spring-boot 应用程序,但我无法在 Intellij IDE 上启动调试器模式。

我收到以下错误

Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

Picked up _JAVA_OPTIONS: -Xmx512M
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jedisConnectionFactory' defined in class path resource [com/fedex/ground/transportation/fxglhlschedulesvc/config/RedisConfig.class]: Unsatisfied dependency expressed through method 'jedisConnectionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisProperties' defined in file [C:\Users\3895631\Desktop\Repo\fxg-lhl-schedule-svc\build\classes\java\main\com\fedex\ground\transportation\fxglhlschedulesvc\config\RedisProperties.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.redis.port' in value "${spring.redis.port}"

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisProperties' defined in file [C:\Users\3895631\Desktop\Repo\fxg-lhl-schedule-svc\build\classes\java\main\com\fedex\ground\transportation\fxglhlschedulesvc\config\RedisProperties.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.redis.port' in value "${spring.redis.port}"

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.redis.port' in value "${spring.redis.port}"

RedisConfig 类


@Configuration
@EnableRedisRepositories
public class RedisConfig {

    @Value("${spring.redis.password:}")
    private String redisPassword;

    @Bean
    @Primary
    JedisConnectionFactory jedisConnectionFactory(RedisProperties redisProperties) {
        RedisStandaloneConfiguration redisStandaloneConfiguration =
                new RedisStandaloneConfiguration(redisProperties.getRedisHost(), redisProperties.getRedisPort());
        redisStandaloneConfiguration.setPassword(RedisPassword.of(redisPassword));
        return new JedisConnectionFactory(redisStandaloneConfiguration);
    }

    @Bean
    public RedisTemplate<String, Object> redisTemplate(JedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory);
        return template;
    }

}

RedisProperties 类


@Configuration
public class RedisProperties {
    private final int redisPort;
    private final String redisHost;

    public RedisProperties(
            @Value("${spring.redis.port}") int redisPort,
            @Value("${spring.redis.host:localhost}") String redisHost) {
        this.redisPort = redisPort;
        this.redisHost = redisHost;
    }

    public int getRedisPort() {
        return redisPort;
    }

    public String getRedisHost() {
        return redisHost;
    }
}

应用程序 - 属性

spring:
  profiles: local
  redis:
    host: localhost
    port: 6340
  application:
    name: fxg-lhl-schedule-svc
server.port: 9092

在这一点上,我遵循并尝试了类似故障排除线程上的大多数解决方案,但到目前为止还没有运气。

我想知道如何解决这个问题?

标签: javaspringspring-boottomcatredis

解决方案


提供如下默认值 -

@Value("${spring.redis.port:6340}")


推荐阅读