1

如果声明了会话对象,则会话对象的自动装配属性不会自动装配

<bean id="user" class="org.User" scope="session">
    <aop:scoped-proxy/>
</bean>

用户对象属性是@autowired,但该属性没有自动装配。

public class User 
{
    TemplateService templateService;

    @Autowired
    public void setTemplateService(TemplateService templateService) {
        this.templateService = templateService;
    }
}

我想知道为什么会这样。用 xml 声明替换自动装配注释是唯一的解决方案。还有其他解决方案吗?谢谢

4

0 回答 0