Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring servletcontext无法访问根应用程序上下文中的bean_Java_Xml_Spring - Fatal编程技术网

Java Spring servletcontext无法访问根应用程序上下文中的bean

Java Spring servletcontext无法访问根应用程序上下文中的bean,java,xml,spring,Java,Xml,Spring,我在根applicationcontext中有一个bean,但dispatcherServlet似乎无法访问该bean。 我有一种感觉,我所理解的根applicationcontext并不是真正的根上下文。 根据我的理解,appcontext-config.xml中定义的任何内容都在根上下文中。servlet-config.xml中定义的任何内容都在servlet上下文中。这是真的吗 有人能在下面的配置中看到任何错误吗 下面我只举了一个bean作为例子,但我确实看到在导入的xmls中定义的bea

我在根applicationcontext中有一个bean,但dispatcherServlet似乎无法访问该bean。 我有一种感觉,我所理解的根applicationcontext并不是真正的根上下文。 根据我的理解,appcontext-config.xml中定义的任何内容都在根上下文中。servlet-config.xml中定义的任何内容都在servlet上下文中。这是真的吗

有人能在下面的配置中看到任何错误吗

下面我只举了一个bean作为例子,但我确实看到在导入的xmls中定义的bean在某些情况下被多次定义

有什么想法吗

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>

           /WEB-INF/appcontext-config.xml
        </param-value>
    </context-param> 
    <listener>
        <listener-class>
 org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
<servlet>
    <servlet-name>sw</servlet-name>
        <servlet-class>
org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/servlet-config.xml
            </param-value>
        </init-param>
</servlet>
</web-app>

上下文配置位置
/WEB-INF/appcontext-config.xml
org.springframework.web.context.ContextLoaderListener
西南
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/servlet-config.xml
appcontext-config.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:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

<bean id="environmentPropertyConfigurer" class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryption"/>
    <property name="location" value="classpath:environment.properties"/>
</bean>

<context:component-scan base-package="com.a.b.*">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<context:annotation-config/>

<tx:annotation-driven transaction-manager="transactionManager"/>

<import resource="general-config.xml"/>
</beans>
<?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:camel="http://camel.apache.org/schema/spring"
    xmlns:webflow="http://www.springframework.org/schema/webflow-config"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"


xsi:schemaLocation="    
    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/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema
    /spring/camel-spring-2.4.0.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/
    spring-webflow-config-2.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">
<mvc:annotation-driven content-negotiation
 manager="contentNegotiationManager">
    <mvc:message-converters>
     <bean
       class="org.springframework.http.
       converter.json.MappingJackson2HttpMessageConverter">
        <property name="objectMapper">
     <bean
 class="com.a.b.service.dataaccess.HibernateAwareObjectMapper" />
 </property>
 </bean>
 </mvc:message-converters>  
 </mvc:annotation-driven>
 <bean id="contentNegotiationManager" 
 class="org.springframework.web.accept.
 ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="false" />
 </bean>
 <context:component-scan base-package="com.a.b.*" 
 use-default-filters="false">
 <context:include-filter type="annotation"
 expression="org.springframework.stereotype.Controller"/>
 </context:component-scan>
 <context:annotation-config/>
 <import resource="servlet-general-config.xml"/>
 </beans>

servlet-config.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:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd">

<bean id="environmentPropertyConfigurer" class="org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer">
    <constructor-arg ref="configurationEncryption"/>
    <property name="location" value="classpath:environment.properties"/>
</bean>

<context:component-scan base-package="com.a.b.*">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<context:annotation-config/>

<tx:annotation-driven transaction-manager="transactionManager"/>

<import resource="general-config.xml"/>
</beans>
<?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:camel="http://camel.apache.org/schema/spring"
    xmlns:webflow="http://www.springframework.org/schema/webflow-config"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"


xsi:schemaLocation="    
    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/context
    http://www.springframework.org/schema/context/spring-context-3.2.xsd
    http://camel.apache.org/schema/spring http://camel.apache.org/schema
    /spring/camel-spring-2.4.0.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/
    spring-webflow-config-2.3.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">
<mvc:annotation-driven content-negotiation
 manager="contentNegotiationManager">
    <mvc:message-converters>
     <bean
       class="org.springframework.http.
       converter.json.MappingJackson2HttpMessageConverter">
        <property name="objectMapper">
     <bean
 class="com.a.b.service.dataaccess.HibernateAwareObjectMapper" />
 </property>
 </bean>
 </mvc:message-converters>  
 </mvc:annotation-driven>
 <bean id="contentNegotiationManager" 
 class="org.springframework.web.accept.
 ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="false" />
 </bean>
 <context:component-scan base-package="com.a.b.*" 
 use-default-filters="false">
 <context:include-filter type="annotation"
 expression="org.springframework.stereotype.Controller"/>
 </context:component-scan>
 <context:annotation-config/>
 <import resource="servlet-general-config.xml"/>
 </beans>

看起来像bean reference
configurationEncryption
不在
general config.xml

另请注意:
context:component scan
执行
context:annotation config
的工作,因此可以删除后者