私は、Springアプリケーションを使用する既存のアプリケーションと、xmlファイル内のプレースホルダの.propertiesファイルを使用しています。 現在、Springブートアプリケーションを使用して、既存のビジネスロジックを妨げないでapplicationcontext.xmlをインポートすることを計画しています。以下SpringブートからApplicationContext.xmlを呼び出す
@Configuration
@ComponentScan
@ImportResource("classpath:applicationContext.xml")
public class ApplicationLoading
3.私のapplicationContext.xmlをファイルで以下のように与えた構成クラスで
@SpringBootApplication(scanBasePackages = "com.config")
@RestController
@EnableConfigurationProperties(servicesProperties.class)
public class servicesApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(servicesApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(servicesApplication.class, args);
}
@RequestMapping("/")
String home() {
return "This is the first program in fixedservices!";
}
}
2:以下の変更
1.メインサービスクラスがあります
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-lazy-init="true">
<context:component-scan
base-package="com.model" />
<!-- CXF QPS SERVICE CLIENT SPRINT SETUP (START) -->
<bean
class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:config/application-local.yml
</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<jaxws:client id="qpsServiceClient"
serviceClass="com.qpssoapservice.client.QPSService"
address="${qps_url}">
<jaxws:outInterceptors>
<bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="UsernameToken" />
<entry key="user" value="${username}" />
<entry key="passwordType" value="PasswordText" />
<entry key="passwordCallbackRef" value-ref="passwordCallback" />
</map>
</constructor-arg>
</bean>
</jaxws:outInterceptors>
</jaxws:client>
<bean id="passwordCallback"
class="com.qpssoapservice.callback.ClientPasswordCallback">
<property name="userName" value="${username}" />
<property name="password" value="${password}" />
</bean>
<bean name="QPSManager" id="QPSManager" class="com.qps.QPSManager">
<property name="qpsServiceClient" ref="qpsServiceClient" />
</bean>
</beans>
私はYMLファイルを設定しました。以下
私YMLファイルのプロパティである:
spring:
profiles:
active: local
qps_url: https://sample.QPSSoapService
username: abcd
password: xyxys
のTomcatにデプロイするときに私はエラーに直面しています。以下のエラーです:
17:11:24,955 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to WARN
17:11:24,955 |-INFO in [email protected] - Propagating WARN level on Logger[org.springframework] onto the JUL framework
17:11:24,955 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.web] to WARN
17:11:24,955 |-INFO in [email protected] - Propagating WARN level on Logger[org.springframework.web] onto the JUL framework
17:11:24,955 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.thymeleaf] to WARN
17:11:24,955 |-INFO in [email protected] - Propagating WARN level on Logger[org.thymeleaf] onto the JUL framework
17:11:24,955 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
17:11:24,956 |-INFO in org.s[email protected]163b1404 - Registering current configuration as safe fallback point
. ____ _ __ _ _
/\\/___'_ __ _ _(_)_ __ __ _ \ \ \ \
(()\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ))))
' |____| .__|_| |_|_| |_\__, |////
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.6.RELEASE)
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.qpssoapservice.callback.ClientPasswordCallback] for bean with name 'passwordCallback' defined in class path resource [applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.qpssoapservice.callback.ClientPasswordCallback
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qpsServiceClient': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'serviceClass'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.qpssoapservice.client.QPSService]
[ERROR] org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' threw an exception
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot[email protected]6bdc99a0: startup date [Mon Aug 21 17:11:25 PDT 2017]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414)
at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
at `enter code here`org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:556)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:131)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:86)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[ERROR] org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot[email protected]6bdc99a0: startup date [Mon Aug 21 17:11:25 PDT 2017]; root of context hierarchy
注:QPSService、ClientPasswordCallbackクラスの呼び出し元のjarファイルから必要な特性を提供することで。
インポートapplicationcontext.xmlを使用していない状態で正常に動作しています。私はhttps://localhos:8080/のようなサンプルURLを打つことができます。しかし、私はインポートを含む問題が来ている。私はロードするために他の設定を与える必要があったと私はまた、私は間違っているかもしれない場所の所有者が正しく読んでいない疑いがあります。
'com.qpssoapservice.client.QPSService'と' com.qpssoapservice.callback.ClientPasswordCallback'はクラスパス上にありません。エラーはあいまいではありません。彼らはあなたの戦争ファイルにありますか? – Strelok
servicesApplicationクラスに行くと、 'com.qpssoapservice.client。*;'のような 'com.qpssoapservice.client'パッケージをインポートしようとすると、何か試してみるとコンパイルエラーになりますか?そうであれば、 'QPSService'とおそらく' ClientPasswordCallback'はクラスパスにありません。 –
@Strelok u r right、これは私の間違いです。応答ありがとう –