Spring 注释@Transactional不起作用

Spring 注释@Transactional不起作用,spring,hibernate,jsf,transactional,Spring,Hibernate,Jsf,Transactional,我试图使用注解@Transactional来访问我的MySQL,使用Hibernate、Spring和JSF。我的问题是: 当我在managedBean中使用注释@Transactional进行查询时,出现以下错误: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one he

我试图使用注解@Transactional来访问我的MySQL,使用Hibernate、Spring和JSF。我的问题是:

当我在managedBean中使用注释@Transactional进行查询时,出现以下错误:

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:65)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:687)
at br.com.rpg.DAO.AbstractDAO.getCurrentSession(AbstractDAO.java:14)
at br.com.rpg.DAO.CountryDAO.findAll(CountryDAO.java:14)
at br.com.rpg.managedBeans.SignupBean.init(SignupBean.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
我不知道我做错了什么。我的代码和xml配置是:

应用程序配置.xml

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="br.com.rpg.DO" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>
</bean>

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

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

<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

org.hibernate.dialogue.mysqldialogue
假的
我的MB

@Named
@Scope("request")
public class SignupBean implements Serializable {

    private static final long serialVersionUID = 1787096549063029840L;

    @Inject
    private CountryDAO country;

    @Inject
    private UserDAO user;

    private Map<String, Integer> countries;

    private Integer selected;

    private String username;

    private String password;

    @PostConstruct
    @Transactional
    public void init() {
        List<CountryDO> findAll = country.findAll();
        countries = new HashMap<String, Integer>();
        for (CountryDO countryDO : findAll) {
            countries.put(countryDO.getName(), countryDO.getId());
        }
    }

    public Map<String, Integer> getCountries() {
        return countries;
    }

    public void setCountries(Map<String, Integer> countries) {
        this.countries = countries;
    }

    public Integer getSelected() {
        return selected;
    }

    public void setSelected(Integer selected) {
        this.selected = selected;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
@Named
@范围(“请求”)
公共类SignupBean实现了可序列化{
私有静态最终长serialVersionUID=1787096549063029840L;
@注入
私人国家;
@注入
私有用户;
私有地图国家;
选择私有整数;
私有字符串用户名;
私有字符串密码;
@施工后
@交易的
公共void init(){
List findAll=country.findAll();
国家=新HashMap();
for(CountryDO CountryDO:findAll){
countries.put(countryDO.getName(),countryDO.getId());
}
}
国家/地区公共地图(){
返回国;
}
国家/地区(地图国家/地区){
这个国家=国家;
}
公共整数getSelected(){
返回选中的;
}
已选择公共无效设置(已选择整数){
this.selected=selected;
}
公共字符串getUsername(){
返回用户名;
}
public void setUsername(字符串用户名){
this.username=用户名;
}
公共字符串getPassword(){
返回密码;
}
public void setPassword(字符串密码){
this.password=密码;
}
我国刀上有@Named注解,有人能帮我吗


Thx.

您已经在
init
方法上应用了
@PostConstruct
@Transactional
init
方法将在应用任何AOP代理拦截器之前被调用,因为
@PostConstruct
。因此在调用
init
时,没有应用任何事务代理。如果需要在应用程序启动时调用init方法使用
ApplicationEvent

是一个CDI工件,
@Scope
是一个Spring工件-一个讨厌的组合-一个不可依赖的东西。不是吗?
@Transactional
,另一方面,在服务层上使用的是不同的东西r、 然而,我选择对此保持沉默。