gpt4 book ai didi

java - Spring Boot 应用程序无法 Autowiring XML 配置

转载 作者:行者123 更新时间:2023-12-01 12:08:17 25 4
gpt4 key购买 nike

我正在尝试将现有的传统 Spring 应用程序转换为 Spring Boot。我已使用 @ImportResource 导入了 XML 配置,并在运行应用程序时导入。即使这个 bean 是在 XML 配置中配置的,它也会抛出注入(inject)失败。不确定这里出了什么问题

>Application.java

@Configuration
@ComponentScan("com.vzt")
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class Application {

public static void main(String[] args) {

ApplicationContext applicationContext = SpringApplication.run(
Application.class, args);

System.out.println("Let's inspect the beans provided by Spring Boot:");

String[] beanNames = applicationContext.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}

}
}

@Configuration
@ImportResource("classpath:spring/beans.xml")
// @Profile("itest2") //commented it from the suggestion to set the
spring.profiles.active=itest2 on VM arguments
class XMLImportingConfiguration {

}

>XML 配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:web-services="http://www.springframework.org/schema/web-services"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:util="http://www.springframework.org/schema/util"
xmlns:c="http://www.springframework.org/schema/c" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">


<context:component-scan base-package="com.vzt" />

<!-- <oxm:jaxb2-marshaller id="marshaller" contextPath="com.vzt.ws.stubs.cca.ivrinfows"
/> -->


<!-- <jee:jndi-lookup id="ccaDataSource" jndi-name="java:/cca"
resource-ref="true" />
-->

<bean id="ccaDataSourceTest"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="oracle.jdbc.OracleDriver" />
<property name="url" value="${cca.jdbc.url}" />
<property name="username" value="${cca.jdbc.username}" />
<property name="password" value="${cca.jdbc.password}" />
</bean>


<bean id="ccaService" class="com.vzt.callcenter.service.CCAServiceImpl">
<!-- wire dependency -->
</bean>

<bean id="ccaRepository" class="com.vzt.callcenter.dao.CCARepository">
<property name="dataSource" ref="ccaDataSourceTest" />
</bean>

<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<!-- IVR Info WS Request and Response Classes -->
<value>com.vzt.ws.stubs.cca.ivrinfows.CallData</value>
<value>com.vzt.ws.stubs.cca.ivrinfows.GetCallData</value>
<value>com.vzt.ws.stubs.cca.ivrinfows.IvrTransfer</value>
<value>com.vzt.ws.stubs.cca.ivrinfows.IvrTransferred</value>

<!-- Weather Data WS Request and Response Classes -->
<value>com.vzt.ws.stubs.weather.Alert</value>
<value>com.vzt.ws.stubs.weather.DataSet</value>
<value>com.vzt.ws.stubs.weather.GetAll</value>
<value>com.vzt.ws.stubs.weather.GetAllResponse</value>
<value>com.vzt.ws.stubs.weather.Weather</value>

<!-- MW (ESB) Webservice SR Request and Response Classes -->
<value>com.hughestelematics.htimessageheader.MessageHeaderT</value>
<value>com.hughestelematics.xmlns.webservicesr.WebserviceSRRequest
</value>
<value>com.hughestelematics.xmlns.webservicesr.WebserviceSRReturn
</value>

<!-- Siebel Webservice updateSRType Request and Response Classes -->
<value>com.siebel.customui.UpdateSRTypeInput</value>
<value>com.siebel.customui.UpdateSRTypeOutput</value>

<!-- MW (BPEL) Webservice SR PSTN Request and Response Classes -->
<value>com.hti.xmlns.webservicepstn.ObjectFactory</value>
<value>com.hti.xmlns.webservicepstn.PSTNRequestT</value>
<value>com.hti.xmlns.webservicepstn.PSTNReturnT</value>
<value>com.hti.xmlns.webservicepstn.PSTNOutput</value>


</list>
</property>
</bean>

<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">

<property name="marshaller" ref="jaxb2Marshaller" />
<property name="unmarshaller" ref="jaxb2Marshaller" />
<constructor-arg ref="messageFactory" />


<!-- <property name="defaultUri" value="${ccawebservice.url}" /> -->
<property name="messageSender">
<bean
class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
<property name="connectionTimeout" value="${cca.ivrinfo.webservice.timeout}" />
<property name="readTimeout" value="${cca.ivrinfo.webservice.timeout}" />
<property name="acceptGzipEncoding" value="false" />
</bean>
</property>
</bean>

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="messageFactory">
<bean
class="com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl" />
</property>
</bean>


<!-- <mvc:default-servlet-handler /> -->

<mvc:resources location="/resources/" mapping="/resources/**" />

<!-- <mvc:interceptors> <bean class = "com.vzt.nissan.interceptors.HttpRequestResponseLoggingInterceptor"/>
<bean class = "com.vzt.nissan.interceptors.AddSessionBeanInterceptor" />
</mvc:interceptors> -->
<context:annotation-config />

<mvc:annotation-driven />
<aop:aspectj-autoproxy />

<beans profile="dev">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:framework_dev.properties</value>
<value>classpath:data/testdata/testdata_dev.properties</value>
<value>classpath:db/db_dev.properties</value>
</list>
</property>
</bean>
</beans>


<beans profile="itest">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:framework_itest.properties</value>
<value>classpath:data/testdata/testdata_itest.properties</value>
<value>classpath:db/db_itest.properties</value>
</list>
</property>
</bean>
</beans>

<beans profile="itest2">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:framework_itest2.properties</value>
<value>classpath:data/testdata/testdata_itest2.properties</value>
<value>classpath:db/db_itest2.properties</value>
</list>
</property>
</bean>
</beans>

>CCAServiceImpl.java

package com.vzt.callcenter.service;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.soap.client.SoapFaultClientException;
import com.vzt.callcenter.constants.Constants;
import com.vzt.callcenter.model.GetCallDataByInteractionIdResponse;
import com.vzt.ws.stubs.cca.ivrinfows.CallData;
import com.vzt.ws.stubs.cca.ivrinfows.GetCallData;
import com.vzt.ws.stubs.cca.ivrinfows.IvrTransfer;
import com.vzt.ws.stubs.cca.ivrinfows.IvrTransferred;
import com.vzt.ws.stubs.cca.ivrinfows.ObjectFactory;

@Service
public class CCAServiceImpl implements CCAService {

@Autowired
private WebServiceTemplate webServiceTemplate;

static Logger logger = Logger.getLogger(CCAServiceImpl.class);

@Value("${cca.ivrinfo.webservice.url}")
private String webserviceUrl;

@Value("${cca.ivrinfo.webservice.timeout}")
private String webserviceTimeout;

public String getWebserviceUrl() {
return webserviceUrl;
}

public void setWebserviceUrl(String webserviceUrl) {
this.webserviceUrl = webserviceUrl;
}

public String getWebserviceTimeout() {
return webserviceTimeout;
}

public void setWebserviceTimeout(String webserviceTimeout) {
this.webserviceTimeout = webserviceTimeout;
}



/* (non-Javadoc)
* @see com.vzt.callcenter.service.CCAService#getCallDataByInteractionId(java.lang.String)
*/
@Override
public GetCallDataByInteractionIdResponse getCallDataByInteractionId(
String interactionId) {

//code not shown for brevity
return getCallDataByInteractionIdResponse;
}

/* (non-Javadoc)
* @see com.vzt.callcenter.service.CCAService#ivrTransfer(com.vzt.callcenter.model.IvrTransferRequest)
*/
@Override
public String ivrTransfer(com.vzt.callcenter.model.IvrTransferRequest ivrTransferRequest) {

logger.info("Request:" + ivrTransferRequest);

//code not shown for brevity

return Constants.WS_RC_CCAINFOWS_WSEXCEPTION;
}
}

>我执行 Spring Boot 时出错

编辑

Based on USER:axtavt comment, I made change to the
spring.active.profiles on run-time instead of using @Annotations. And
now I get the below error.

org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4260904e: startup date [Thu Dec 11 09:47:19 EST 2014]; root of context hierarchy
09:47:19 DEBUG ntext.embedded.AnnotationConfigEmbeddedWebApplicationContext obtainFreshBeanFactory Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4260904e: org.springframework.beans.factory.support.DefaultListableBeanFactory@4db8738f: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,application]; root of factory hierarchy
09:47:20 INFO rg.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [spring/beans.xml]
09:47:21 INFO ngframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Overriding bean definition for bean 'mvcContentNegotiationManager': replacing [Root bean: class [org.springframework.web.accept.ContentNegotiationManagerFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; factoryMethodName=mvcContentNegotiationManager; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]]
09:47:21 INFO rk.context.annotation.ConfigurationClassBeanDefinitionReader iddenByExistingDefinition Skipping bean definition for [BeanMethod:name=mvcUriComponentsContributor,declaringClass=org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport]: a definition for bean 'mvcUriComponentsContributor' already exists. This top-level bean definition is considered as an override.
09:47:21 INFO ngframework.beans.factory.support.DefaultListableBeanFactory registerBeanDefinition Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
09:47:21 INFO framework.beans.factory.config.PropertyPlaceholderConfigurer loadProperties Loading properties file from class path resource [framework_itest2.properties]
09:47:21 INFO framework.beans.factory.config.PropertyPlaceholderConfigurer loadProperties Loading properties file from class path resource [data/testdata/testdata_itest2.properties]
09:47:21 INFO framework.beans.factory.config.PropertyPlaceholderConfigurer loadProperties Loading properties file from class path resource [db/db_itest2.properties]
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
09:47:22 INFO t.PostProcessorRegistrationDelegate$BeanPostProcessorChecker rocessAfterInitialization Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$acc877c3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
09:47:22 INFO t.PostProcessorRegistrationDelegate$BeanPostProcessorChecker rocessAfterInitialization Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
09:47:22 INFO t.PostProcessorRegistrationDelegate$BeanPostProcessorChecker rocessAfterInitialization Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
09:47:22 INFO t.PostProcessorRegistrationDelegate$BeanPostProcessorChecker rocessAfterInitialization Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
09:47:22 DEBUG ntext.embedded.AnnotationConfigEmbeddedWebApplicationContext initMessageSource Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@773fe60f]
09:47:22 DEBUG ntext.embedded.AnnotationConfigEmbeddedWebApplicationContext plicationEventMulticaster Using ApplicationEventMulticaster [org.springframework.context.event.SimpleApplicationEventMulticaster@4191ff3]
09:47:22 DEBUG ontext.embedded.tomcat.TomcatEmbeddedServletContainerFactory etArchiveFileDocumentRoot Code archive: C:\Users\v579424\.m2\repository\org\springframework\boot\spring-boot\1.1.7.RELEASE\spring-boot-1.1.7.RELEASE.jar
09:47:22 DEBUG ontext.embedded.tomcat.TomcatEmbeddedServletContainerFactory plodedWarFileDocumentRoot Code archive: C:\Users\v579424\.m2\repository\org\springframework\boot\spring-boot\1.1.7.RELEASE\spring-boot-1.1.7.RELEASE.jar
09:47:22 DEBUG ontext.embedded.tomcat.TomcatEmbeddedServletContainerFactory getValidDocumentRoot Document root: C:\Users\v579424\Documents\workspace-sts-3.4.0.RELEASE\VZTCallCenterFramework\src\main\webapp
09:47:22 INFO ontext.embedded.tomcat.TomcatEmbeddedServletContainerFactory tEmbeddedServletContainer Server initialized with port: 8080
09:47:22 INFO org.springframework.web.context.ContextLoader ddedWebApplicationContext Root WebApplicationContext: initialization completed in 3087 ms
09:47:23 INFO pringframework.boot.context.embedded.ServletRegistrationBean onStartup Mapping servlet: 'dispatcherServlet' to [/]
09:47:23 INFO springframework.boot.context.embedded.FilterRegistrationBean configure Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
09:47:26 INFO org.springframework.oxm.jaxb.Jaxb2Marshaller ateJaxbContextFromClasses Creating JAXBContext with classes to be bound [class com.vzt.ws.stubs.cca.ivrinfows.CallData,class com.vzt.ws.stubs.cca.ivrinfows.GetCallData,class com.vzt.ws.stubs.cca.ivrinfows.IvrTransfer,class com.vzt.ws.stubs.cca.ivrinfows.IvrTransferred,class com.vzt.ws.stubs.weather.Alert,class com.vzt.ws.stubs.weather.DataSet,class com.vzt.ws.stubs.weather.GetAll,class com.vzt.ws.stubs.weather.GetAllResponse,class com.vzt.ws.stubs.weather.Weather,class com.hughestelematics.htimessageheader.MessageHeaderT,class com.hughestelematics.xmlns.webservicesr.WebserviceSRRequest,class com.hughestelematics.xmlns.webservicesr.WebserviceSRReturn,class com.siebel.customui.UpdateSRTypeInput,class com.siebel.customui.UpdateSRTypeOutput,class com.hti.xmlns.webservicepstn.ObjectFactory,class com.hti.xmlns.webservicepstn.PSTNRequestT,class com.hti.xmlns.webservicepstn.PSTNReturnT,class com.hti.xmlns.webservicepstn.PSTNOutput]
09:47:27 INFO org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName Loaded JDBC driver: oracle.jdbc.OracleDriver
09:47:27 INFO .springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
09:47:27 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/service/customAgentRoute/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<com.vzt.callcenter.model.CustomRoute> com.vzt.callcenter.web.CustomAgentRouteController.customAgentRoutes()
09:47:27 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/service/customAgentRoute/{mdn}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.vzt.callcenter.model.CustomRoute com.vzt.callcenter.web.CustomAgentRouteController.getCustomRougeByMdn(java.lang.String)
09:47:27 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
09:47:27 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
09:47:28 INFO .springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:47:28 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/service/customAgentRoute/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<com.vzt.callcenter.model.CustomRoute> com.vzt.callcenter.web.CustomAgentRouteController.customAgentRoutes()
09:47:28 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/service/customAgentRoute/{mdn}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public com.vzt.callcenter.model.CustomRoute com.vzt.callcenter.web.CustomAgentRouteController.getCustomRougeByMdn(java.lang.String)
09:47:28 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
09:47:28 INFO b.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
09:47:28 INFO .springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:47:28 INFO .springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
09:47:28 INFO pringframework.jmx.export.annotation.AnnotationMBeanExporter afterPropertiesSet Registering beans for JMX exposure on startup
09:47:28 DEBUG ntext.embedded.AnnotationConfigEmbeddedWebApplicationContext initLifecycleProcessor Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@27b6c151]
09:47:28 DEBUG oconfigure.logging.AutoConfigurationReportLoggingInitializer ogAutoConfigurationReport



09:47:28 ERROR org.springframework.boot.SpringApplication run Application startup failed
java.lang.IllegalStateException: Tomcat connector in failed state
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:154)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:272)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:132)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.vzt.Application.main(Application.java:28)
09:47:28 INFO ntext.embedded.AnnotationConfigEmbeddedWebApplicationContext doClose Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4260904e: startup date [Thu Dec 11 09:47:19 EST 2014]; root of context hierarchy
09:47:28 INFO pringframework.jmx.export.annotation.AnnotationMBeanExporter destroy Unregistering JMX-exposed beans on shutdown
Exception in thread "main" java.lang.IllegalStateException: Tomcat connector in failed state
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.start(TomcatEmbeddedServletContainer.java:154)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.startEmbeddedServletContainer(EmbeddedWebApplicationContext.java:272)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:132)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at com.vzt.Application.main(Application.java:28)
**

最佳答案

通过在 VM 参数上传递 spring.profiles.active=itest2 而不是将其设置为如下所示的注释来修复此问题。不确定,为什么 spring-boot 不允许使用注释进行配置。

@Configuration
@ImportResource("classpath:spring/beans.xml")
@Profile("itest2")
class XMLImportingConfiguration {

}

关于java - Spring Boot 应用程序无法 Autowiring XML 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27425274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com