英文:
Error creating bean with name 'jmsConfiguration'
问题
以下是您提供的代码的翻译部分:
我想要使用一个Springboot Apache Camel应用程序从IBM MQ获取消息。我目前正在设置JMS连接,但我收到一个有关bean的错误。不确定发生了什么,因为我认为bean现在已经被定义。
import com.ibm.mq.MQEnvironment;
import com.ibm.msg.client.wmq.common.CommonConstants;
//import org.apache.camel.component.jms.JmsComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import org.springframework.jms.annotation.EnableJms;
import com.ibm.msg.client.wmq.WMQConstants;
import javax.net.ssl.*;
import java.security.KeyStore;
@EnableJms
@Configuration
public class JmsConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(JmsComponent.class);
private String host = "xxx";
private int port = 4510;
private String queueManager = "xxx";
private String channel = "xxx";
//private String username = "";
//private String password = "";
private String sslCipherSuite = "TLS_RSA_WITH_AES_256_CBC_SHA256";
@Value("${keyStore}")
private String keyStore;
@Value("${keyStorePassword}")
private String keyStorePassword;
@Value("${trustStore}")
private String trustStore;
@Value("${trustStorepassword}")
private String trustStorePassword;
@Bean
public JmsComponent mq() {
JmsComponent jmsComponent = new JmsComponent();
jmsComponent.setConnectionFactory(mqQueueConnectionFactory());
return jmsComponent;
}
@Bean
public MQQueueConnectionFactory mqQueueConnectionFactory() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName(host);
try {
//Load trust store
//System.setProperty("javax.net.ssl.trustStore", trustStore);
//System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
//Load keystore
//System.setProperty("javax.net.ssl.keyStore", keyStore);
//System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
//keystore fetch
String keystoreKey = "${keyStorePassword}";
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("${keyStore}"),
keystoreKey.toCharArray());
// Create key manager
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, keystoreKey.toCharArray());
KeyManager[] km = keyManagerFactory.getKeyManagers();
// Create trust manager
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
trustManagerFactory.init(keyStore);
TrustManager[] tm = trustManagerFactory.getTrustManagers();
// Initialize SSLContext
SSLContext sslContext = SSLContext.getInstance("TLSv1");
sslContext.init(km, tm, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
mqQueueConnectionFactory.setPort(port);
mqQueueConnectionFactory.setChannel(channel);
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setObjectProperty(WMQConstants.WMQ_SSL_SOCKET_FACTORY, sslSocketFactory);
mqQueueConnectionFactory.setSSLCipherSuite(sslCipherSuite);
mqQueueConnectionFactory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setTransportType(CommonConstants.WMQ_CM_BINDINGS);
MQEnvironment.sslSocketFactory = sslSocketFactory;
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
}
这是您提供的堆栈跟踪的一部分,它显示了一个与bean相关的错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConfiguration': Injection of autowired dependencies failed
...
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'keyStore' in value "${keyStore}"
...
请注意,这里显示了一个无法解析占位符“keyStore”的错误。这可能是因为在您的应用程序配置文件中缺少了相应的属性,或者属性没有正确配置。您需要确保配置文件中包含正确的属性值。
英文:
I want to use a Springboot Apache Camel application to get a message on IBM MQ. I am currently setting up the JMS connection, but I receive an error about a bean. Not sure what is going on because I thought that de bean is being defined now.
import com.ibm.mq.MQEnvironment;
import com.ibm.msg.client.wmq.common.CommonConstants;
//import org.apache.camel.component.jms.JmsComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import org.springframework.jms.annotation.EnableJms;
import com.ibm.msg.client.wmq.WMQConstants;
import javax.net.ssl.*;
import java.security.KeyStore;
@EnableJms
@Configuration
public class JmsConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(JmsComponent.class);
private String host = "xxx";
private int port = 4510;
private String queueManager = "xxx";
private String channel = "xxx";
//private String username = "";
//private String password = "";
private String sslCipherSuite = "TLS_RSA_WITH_AES_256_CBC_SHA256";
@Value("${keyStore}")
private String keyStore;
@Value("${keyStorePassword}")
private String keyStorePassword;
@Value("${trustStore}")
private String trustStore;
@Value("${trustStorepassword}")
private String trustStorePassword;
@Bean
public JmsComponent mq() {
JmsComponent jmsComponent = new JmsComponent();
jmsComponent.setConnectionFactory(mqQueueConnectionFactory());
return jmsComponent;
}
@Bean
public MQQueueConnectionFactory mqQueueConnectionFactory() {
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName(host);
try {
//Load trust store
//System.setProperty("javax.net.ssl.trustStore", trustStore);
//System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
//Load keystore
//System.setProperty("javax.net.ssl.keyStore", keyStore);
//System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
//keystore fetch
String keystoreKey = "${keyStorePassword}";
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("${keyStore}"),
keystoreKey.toCharArray());
// Create key manager
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(keyStore, keystoreKey.toCharArray());
KeyManager[] km = keyManagerFactory.getKeyManagers();
// Create trust manager
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("SunX509");
trustManagerFactory.init(keyStore);
TrustManager[] tm = trustManagerFactory.getTrustManagers();
// Initialize SSLContext
SSLContext sslContext = SSLContext.getInstance("TLSv1");
sslContext.init(km, tm, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
mqQueueConnectionFactory.setPort(port);
mqQueueConnectionFactory.setChannel(channel);
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setObjectProperty(WMQConstants.WMQ_SSL_SOCKET_FACTORY, sslSocketFactory);
mqQueueConnectionFactory.setSSLCipherSuite(sslCipherSuite);
mqQueueConnectionFactory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setTransportType(CommonConstants.WMQ_CM_BINDINGS);
MQEnvironment.sslSocketFactory = sslSocketFactory;
} catch (Exception e) {
e.printStackTrace();
}
return mqQueueConnectionFactory;
}
}
This is the stacktrace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConfiguration': Injection of autowired dependencies failed
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:489) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1416) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:597) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941) ~[spring-context-6.0.10.jar!/:6.0.10]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.10.jar!/:6.0.10]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.8.jar!/:3.0.8]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.8.jar!/:3.0.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.8.jar!/:3.0.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.8.jar!/:3.0.8]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.8.jar!/:3.0.8]
at nl.rabobank.mqputter.MqPutterApplication.main(MqPutterApplication.java:10) ~[classes!/:0.0.1-SNAPSHOT]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:95) ~[app.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[app.jar:0.0.1-SNAPSHOT]
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'keyStore' in value "${keyStore}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-6.0.10.jar!/:6.0.10]
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126) ~[spring-core-6.0.10.jar!/:6.0.10]
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239) ~[spring-core-6.0.10.jar!/:6.0.10]
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210) ~[spring-core-6.0.10.jar!/:6.0.10]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties$0(PropertySourcesPlaceholderConfigurer.java:191) ~[spring-context-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:920) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1358) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1337) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:711) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:694) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.0.10.jar!/:6.0.10]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:483) ~[spring-beans-6.0.10.jar!/:6.0.10]
... 24 common frames omitted
答案1
得分: 1
错误很明显:
> 在值中无法解析占位符'keyStore' "${keyStore}"
这意味着您尚未在任何地方设置该属性。
请注意,您可以为缺失的属性添加默认值 "${keyStore:someDefault}"
。
英文:
The error is quite obvious:
>Could not resolve placeholder 'keyStore' in value "${keyStore}"
It means that you have not set that property anywhere.
Note that you can add a default value for a missing property "${keyStore:someDefault}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论