Spring 创建ApplicationContext.xml中定义的bean时出错
我正在将Spring(v.4.3.2)应用程序从Tomcat7移植到Tomcat9。我正在Windows box上运行Tomcat作为服务。在ApplicationContext.xml中,我定义了几个bean配置文件,并且在配置文件之外还有bean定义:Spring 创建ApplicationContext.xml中定义的bean时出错,spring,tomcat,applicationcontext,Spring,Tomcat,Applicationcontext,我正在将Spring(v.4.3.2)应用程序从Tomcat7移植到Tomcat9。我正在Windows box上运行Tomcat作为服务。在ApplicationContext.xml中,我定义了几个bean配置文件,并且在配置文件之外还有bean定义: <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManag
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="utilsDS" />
</bean>
创建名为“transactionManager”的bean时出错,该bean在ServletContext资源[/WEB-INF/config/applicationContext.xml]中定义:
设置bean属性“dataSource”时无法解析对bean“utilsDS”的引用;
嵌套异常为org.springframework.beans.factory.NoSuchBeanDefinitionException:
未定义名为“utilsDS”的bean
Tomcat7和9上的“applicationContext.xml”是相同的,因为我使用了相同的WAR来部署应用程序。我不确定我错过了什么。
在我看来,Tomcat9的配置中有一些东西可以解决引用问题。我不确定它是什么。我将上下文参数添加到应用程序“web.xml”中,它可以工作:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
spring.profiles.active
发展
仍然不确定为什么要传递JVM选项:
-Dspring.profiles.active=dev
没用
</beans>
org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>