0
我有现有的应用程序使用spring应用程序和.properties文件的占位符在xml文件中。 现在,我们正计划使用spring引导应用程序来导入spring applicationcontext.xml,而不会出现令人不安的现有业务逻辑。下面是变化从Spring引导调用Applicationcontext.xml
1.主要服务类:
@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.配置类给像下面
@Configuration
@ComponentScan
@ImportResource("classpath:applicationContext.xml")
public class ApplicationLoading
低于3是我applicationContext.xml文件
<?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 ch.qos.logback.classic.jul.LevelChangeP[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,从jar文件ClientPasswordCallback类调用提供所需的性能。
带出使用导入applicationcontext.xml它工作正常。我可以打样品网址,如https://localhos:8080/。但是当我包含导入问题即将到来。我是否需要提供任何其他配置来加载,并且我怀疑占位符不能正确读取,但我可能会错误。
'com.qpssoapservice.client.QPSService'和'com.qpssoapservice.callback.ClientPasswordCallback'不在类路径中。错误是毫不含糊的。他们是否在你的战争档案中? – Strelok
尝试一下,如果你去servicesApplication类,你可以尝试导入'com.qpssoapservice.client'包装像这样'import com.qpssoapservice.client。*;'它会给你一个编译错误吗?如果是'QPSService',也许'ClientPasswordCallback'不在类路径中。 –
@Strelok对了,这是我的错。感谢您的回应 –