从Spring boot

时间:2017-08-22 00:48:39

标签: spring spring-mvc spring-boot

我有使用spring应用程序的现有应用程序和xml文件中占位符的.properties文件。    现在,我们计划使用spring boot应用程序导入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 ch.qos.logback.classic.jul.LevelChangePropagator@5becdd30 - 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.LevelChangePropagator@5becdd30 - 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 ch.qos.logback.classic.jul.LevelChangePropagator@5becdd30 - 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.springframework.boot.logging.logback.SpringBootJoranConfigurator@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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6bdc99a0: startup date [Mon Aug 21 17:11:25 PDT 2017]; root of context hierarchy

注意: QPSService,ClientPasswordCallback类通过提供必需的属性从jar文件调用。

没有使用import applicationcontext.xml它工作正常。我可以像https://localhos:8080/那样点击示例网址。但当我有包含导入问题即将到来。我是否需要提供任何其他配置加载,我也怀疑持有人没有正确阅读,但我可能错了。

1 个答案:

答案 0 :(得分:0)

感谢大家。这是我的错误,jar文件不在战争中。现在问题得到了解决。