英文:
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 '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:\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 '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:\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 '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 class
@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 class
@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
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("${spring.redis.port:6340}")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论