Spring 3.1中注入资源依赖性失败

时间:2012-10-15 19:29:34

标签: spring autowired

感谢有关注入依赖项错误的任何帮助。当bean独立时,同样的事情完全有效。在apache 6.0.35启动期间,它会抛出以下内容。感谢任何帮助,并提前感谢。我使用的是Spring 3.1.1

**SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appConfigBean': Injection of resource dependencies failed; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ExtConfigBean' is defined**

完整的代码和配置如下:

Java代码

    @Configuration
@PropertySource("classpath:application.properties")
@Component
@Service
public class AppConfig implements ApplicationConstants, ApplicationContextAware {

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * Main Map Bean
     */
    @Resource(name = "ExtConfigBean")
    private LinkedHashMap<String, String> extConfigBeanMap;

        @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("Autowiring Context Ref: " + applicationContext);
        this.applicationContext = applicationContext;
    }
}

application.properties

application=ApplicationTest
version=1.0.0
release=July 2012

ApplicationContext文件是

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/util 
       http://www.springframework.org/schema/util/spring-util-2.0.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
       http://www.springframework.org/schema/aop 
       http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
       http://www.springframework.org/schema/lang 
       http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/oxm
       http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
       http://www.springframework.org/schema/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

    <!-- Configures the @Controller programming model -->
    <mvc:annotation-driven />

    <!-- Activates scanning of @Autowired -->
    <context:annotation-config />
    <!-- <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /> -->

    <!-- Activates scanning of @Repository and @Service -->
    <context:component-scan
        base-package="com.app.test ">
    </context:component-scan>

    <!-- Application wide Spring Injection -->
    <bean id="contextProvider" class="com.app.test.AppContextProvider" lazy-init="false" />

    <bean id="appConfigBean" class="com.app.test.config.AppConfig" lazy-init="false" />


        <!-- Application Configuration -->
    <bean id="ExtConfigBean" class="org.springframework.beans.factory.config.MapFactoryBean">
        <property name="sourceMap">
            <map>
                <entry key="some_key">
                    <value>Some Key Value</value>
                </entry>
            </map>
        </property>
    </bean>
</beans>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“&GT;

<!-- Java-based Spring container definition -->
<context-param>
    <param-name>contextClass</param-name>
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>

<!-- Location of Java @Configuration classes that configure the components 
    that makeup this application -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.xxx.ealert.app.config</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<!-- Secures the application -->
<filter>
    <filter-name>securityFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
        <param-name>targetBeanName</param-name>
        <param-value>springSecurityFilterChain</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>securityFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Reads request input using UTF-8 encoding -->
<filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

0 个答案:

没有答案