Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
Spring 不能得到春豆吗?_Spring - Fatal编程技术网

Spring 不能得到春豆吗?

Spring 不能得到春豆吗?,spring,Spring,无法从侦听器或筛选器类中的spring容器中获取bean。您是否使用过类似的方法: @Autowired private ApplicationContext context; ICustomer customer = (ICustomer) context.getBean("name"); // here name is the name of the bean you want to get context 看,我在我的项目中使用了这个,就像这个ans工作得很好: String proc

无法从侦听器或筛选器类中的spring容器中获取bean。

您是否使用过类似的方法:

@Autowired
private ApplicationContext context;

ICustomer customer = (ICustomer) context.getBean("name"); // here name is the name of the bean you want to get context
看,我在我的项目中使用了这个,就像这个ans工作得很好:

String processorName = Introspector.decapitalize(command.getClass().getSimpleName() + "Processor");
ICommandProcessor processor = (ICommandProcessor) context.getBean(processorName);
这里,如果我传递
命令
Add
,那么它将传递
processorName=AddProcessor
,并获取它的上下文

你的要求是什么?你能帮我寄密码吗

查看此xml文件,然后从中检查您的xml文件:

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">            
            <property name="packagesToScan" value="com.domain"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.generate_statistics">true</prop>
                </props>
            </property>
        </bean>

<!-- Transaction Manager -->
    <bean id="txManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

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

org.hibernate.dialogue.PostgreSqlDialogue
真的
真的
真的

这里:
在我的项目中使用
@Autowired
时非常重要,它是
com.domain
,因此请参考此内容并根据需要进行更改。然后再次发布。

向我们展示如何在过滤器中实现它。但我只能获取spring xml中定义的bean名称,无法获取自动连接的bean…您是否制作了该bean的接口并在类中实现了它们?所有接口都实现了。现在工作正常了吗?您做了哪些更改?我想知道注释注入是否与xml手动注入不同?当tomcat启动时,注释扫描类型将仅初始化SpringXML中手动定义的bean;若您在SpringXML中配置bean,那个么所有bean在服务器启动时都是init的。对吗?