WebServerException: 无法启动嵌入式Tomcat

huangapple go评论74阅读模式
英文:

WebServerException: Unable to start embedded Tomcat

问题

以下是翻译好的部分:

我想调试我的 Spring Boot 应用程序,但是我无法在 IntelliJ IDE 上启动调试器模式。

我得到以下错误:

Caused by: org.springframework.boot.web.server.WebServerException: 无法启动嵌入式 Tomcat 服务器

Picked up _JAVA_OPTIONS: -Xmx512M
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: 在类路径资源 [com/fedex/ground/transportation/fxglhlschedulesvc/config/RedisConfig.class] 中定义的名为 'jedisConnectionFactory' 的 Bean 创建失败:通过方法 'jedisConnectionFactory' 表达的不满足的依赖项,参数为 0;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在文件 [C:\Users95631\Desktop\Repo\fxg-lhl-schedule-svc\build\classes\java\main\com\fedex\ground\transportation\fxglhlschedulesvc\config\RedisProperties.class] 中定义的名为 'redisProperties' 的 Bean 创建失败:在创建 Bean 时出现意外异常;嵌套异常是 java.lang.IllegalArgumentException:无法解析值中的占位符 'spring.redis.port':"${spring.redis.port}"

Caused by: org.springframework.beans.factory.BeanCreationException: 在文件 [C:\Users95631\Desktop\Repo\fxg-lhl-schedule-svc\build\classes\java\main\com\fedex\ground\transportation\fxglhlschedulesvc\config\RedisProperties.class] 中定义的名为 'redisProperties' 的 Bean 创建失败:在创建 Bean 时出现意外异常;嵌套异常是 java.lang.IllegalArgumentException:无法解析值中的占位符 'spring.redis.port':"${spring.redis.port}"

Caused by: java.lang.IllegalArgumentException: 无法解析值中的占位符 'spring.redis.port':"${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;
    }
}

application.properties

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

到目前为止,我已经尝试了大部分类似问题的解决方案,但是迄今为止都没有成功。

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

英文:

I want to debug my spring-boot application but I couldnt launch the debugger mode on Intellij IDE.

I am getting following errors

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 &#39;jedisConnectionFactory&#39; defined in class path resource [com/fedex/ground/transportation/fxglhlschedulesvc/config/RedisConfig.class]: Unsatisfied dependency expressed through method &#39;jedisConnectionFactory&#39; parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;redisProperties&#39; defined in file [C:\Users95631\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 &#39;spring.redis.port&#39; in value &quot;${spring.redis.port}&quot;

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;redisProperties&#39; defined in file [C:\Users95631\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 &#39;spring.redis.port&#39; in value &quot;${spring.redis.port}&quot;

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder &#39;spring.redis.port&#39; in value &quot;${spring.redis.port}&quot;

RedisConfig class


@Configuration
@EnableRedisRepositories
public class RedisConfig {

    @Value(&quot;${spring.redis.password:}&quot;)
    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&lt;String, Object&gt; redisTemplate(JedisConnectionFactory connectionFactory) {
        RedisTemplate&lt;String, Object&gt; template = new RedisTemplate&lt;&gt;();
        template.setConnectionFactory(connectionFactory);
        return template;
    }

}

RedisProperties class


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

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

    public int getRedisPort() {
        return redisPort;
    }

    public String getRedisHost() {
        return redisHost;
    }
}

application - properties

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

At this point I followed and tried most of the solutions that are out there on similar troubleshooting threads but no luck so far.

I want to know how can I resolve this?

答案1

得分: 0

提供一个默认值,如下所示 -

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

英文:

Provide a default value like below -

@Value(&quot;${spring.redis.port:6340}&quot;)

huangapple
  • 本文由 发表于 2020年10月1日 00:41:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64142072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定