各位请看我下面的一段代码:ServletContext servletContext = session.getServletContext();
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
// FDService service = (FDService)wac.getBean(className);
// sr = service.execute(request);
Object service = wac.getBean(className);//获得className的实例
这里我在网上面找 都有一个配置了bean的xml文件 可是我这个项目找不到 但是那个getBean也是能取到值的 ,我想知道这个getBean(className)的内部是不是通过java反射取出值的?不需要配置xml文件也是能执行的?
参数className是一个String类型的参数

解决方案 »

  1.   

    可定会有个xml的 只是你没找到在哪配置 看是不是本地的xml 还是远程的xml参考文段
    在使用spring容器的web应用中,业务对象间的依赖关系都可以用context.xml文件来配置,并且由spring容器来负责依赖对象  的创建。如果要在filter或者servlet中使用spring容器管理业务对象,通常需要使用WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext())来获得WebApplicationContext,然后调用WebApplicationContext.getBean("beanName")来获得对象的引用,这实际上是使用了依赖查找来获得对象
      

  2.   

    Spring 包中的一个公用类,一般用来获取,web上下文的信息 ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext()); 得到web应用的上下文信息,填入的参数,是由struts2,所提供的当前servlet上下文的信息。
      

  3.   

    这个是公司的框架 我找了很久 就是没有找到配置的关于bean的xml 包括context 还有用到webservice的 cxf+Spring的配置文件 struts-config  还有web.xml都看了 有一些是配置bean 可是都是拦截器 没有找到我要的那个参数一样的bean  如果是远程的 那是什么意思?
      

  4.   


    <?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
    default-autowire="byName">
    <context:component-scan base-package="com.friendone.ws.*" />
    <context:component-scan base-package="com.friendone.services.*" />
    <context:component-scan base-package="com.friendone.listener.*" />

    <context:property-placeholder location="classpath:jdbc.properties" />

    <bean  id="applicationContextProvider" class="com.friendone.common.SpringContextUtil"></bean>
    <!-- jBPM4 configuration -->

    <!-- jdbcTemplate configuration -->
        <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="maxActive" value="200"/>
            <property name="maxIdle" value="0"/>
            <property name="maxWait" value="-1"/>
        </bean>
    <bean id="jdbctxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean>

    <import resource="classpath:spring-cxf-*.xml" /> <tx:annotation-driven transaction-manager="jdbctxManager"/>

    </beans>
    这个就是context里面的内容没有 和我需要的那个相关的bean
      

  5.   

    我知道了 <context:component-scan base-package="com.friendone.ws.*" />
        <context:component-scan base-package="com.friendone.services.*" />
        <context:component-scan base-package="com.friendone.listener.*" />就是这个东西 把所有的bean都隐式注入了