@PostConstruct未调用(Primefaces& Spring& Hibernate)

时间:2015-11-21 15:50:16

标签: spring hibernate jsf primefaces postconstruct

我正在使用Hibernate,Spring和Primefaces(和Maven)而我正在尝试运行

@PostConstruct
init() {}

初始化bean内的位置列表。但是从不调用init()方法。项目结构是:

com.xxx
com.xxx.hibernate.dao
com.xxx.hibernate.dao.impl
com.xxx.hibernate.data
com.xxx.prime.faces.bean
com.xxx.spring.service
com.xxx.spring.service.impl

应用程序上下文:

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

<context:property-placeholder location="classpath*:META-INF/*.properties"/>
<!-- Scan for all of Spring components such as Spring Service -->
<context:component-scan base-package="com.xxx"></context:component-scan>

<!-- Create Data Source bean -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://host:3306/db" />
    <property name="username" value="user" />
    <property name="password" value="password" />
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property value="persistenceUnit" name="persistenceUnitName" />
    <property name="dataSource" ref="dataSource" />
</bean>

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

<bean id="transactionManager"
    class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<!-- Detect @Transactional Annotation -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>

LocationView Bean:

@ManagedBean
@ViewScoped
public class LocationView implements Serializable{

    private static final long serialVersionUID = 1L;

    @ManagedProperty("#{locationService}")
    private LocationService locationService;

    private Location location = new Location();

    private List<Location> locations = new ArrayList<Location>();

    @PostConstruct
    public void init() {
        this.locations = locationService.getAllLocations();
    }

我在调试模式下在Glassfish4上运行它,并且从不调用init()方法。但我不是没有原因。它应该扫描弹簧注释,但我不知道我怎么能确定。

我也不确定是什么

<context:property-placeholder location="classpath*:META-INF/*.properties"/>

确实

我能检查什么想法?

0 个答案:

没有答案
相关问题