依存関係の注入エラーに関するヘルプに感謝します。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=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">
<!-- 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>