简体   繁体   English

bean定义未加载到Spring上下文中

[英]bean definition is not loading into spring context

I defined the beans definition in country-sg.xml file which I placed in the src/main/resources 我在放置在src / main / resources中的country-sg.xml文件中定义了bean定义。

Created the root-context.xml and imported above file as , I added root-context file web.xml file. 创建了root-context.xml并将其导入为上述文件,我添加了root-context文件web.xml文件。

country-sg.xml file is not loading into context. country-sg.xml文件未加载到上下文中。

Can anyone help how to load this configuration file. 任何人都可以帮助如何加载此配置文件。

Thanks in advance. 提前致谢。

root-context.xml file : root-context.xml文件:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

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

    <mvc:annotation-driven />
    <import resource="classpath*: /country-sg.xml"/>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

country-sg.xml file: country-sg.xml文件:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <bean id="sg" class="com.kachakayala.services.CountrySg"></bean>

</beans>

In order to add the Bean sg in the application context, you have to scan the the configuration class country-sg.xml first. 为了在应用程序上下文中添加Bean sg ,您必须首先扫描配置类country-sg.xml You can achieve this by adding the annotation @ComponentScan("package-of-your-config.xml") at your main class definition header. 您可以通过在主类定义标题中添加注解@ComponentScan("package-of-your-config.xml")来实现此目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM