关于spring+jsf 的bean 的配置问题!请高手指教!谢谢

06-03-10 xxxzheng
首先我在spring 的applicationcontext.xml中创建了testService bean

<bean id="testService" class="jobcn.model.service.impl.gzPerdotServiceImpl">

<property name="gzperdotdao"><ref local="gzperdotdao"/></property>

</bean>我在我的日志文件中找到说明创建testService 成功

log:15:27:22,312 INFO SQLErrorCodesFactory:167 - Database product name found in cache {1321194}. Name is Microsoft SQL Server

15:27:22,312 INFO DefaultListableBeanFactory:158 - Creating shared instance of singleton bean 'gzperdotService'

15:27:22,312 INFO DefaultListableBeanFactory:158 - Creating shared instance of singleton bean 'testService'

在我的jsf bean 中需要使用这个bean testService. 我在jsf中的face-config.xml文件也配置了这个property

<managed-bean>

<managed-bean-name>gzperdotBean</managed-bean-name>

<managed-bean-class>jobcn.view.bean.gzPerdotBean</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

<managed-property>

<property-name>testService</property-name>

<value>#{testService}</value>

</managed-property>

</managed-bean>

但问题总是说我的testService is null 所以就出现了java.lang.NullPointerException这个异常!

请高人指点

web.xml

<web-app>

<context-param>

<param-name>javax.faces.STATE_SAVING_METHOD</param-name>

<param-value>server</param-value>

</context-param>

<context-param>

<param-name>javax.faces.CONFIG_FILES</param-name>

<param-value>/WEB-INF/faces-config.xml</param-value>

</context-param>

<servlet>

<servlet-name>SpringContextServlet</servlet-name>

<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<listener>

<listener-class>com.sun.faces.config.ConfigureListener</listener-class>

</listener>

<servlet>

<servlet-name>Faces Servlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>Faces Servlet</servlet-name>

<url-pattern>*.faces</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

face-config.xml

<faces-config>

<managed-bean>

<managed-bean-name>gzperdotBean</managed-bean-name>

<managed-bean-class>jobcn.view.bean.gzPerdotBean</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

<managed-property>

<property-name>gzperdotService</property-name>

<value>#{gzperdotService}</value>

</managed-property>

<managed-property>

<property-name>testService</property-name>

<value>#{testService}</value>

</managed-property>

</managed-bean>

<managed-bean>

<managed-bean-name>gzperdotListBean</managed-bean-name>>

<managed-bean-class>jobcn.view.bean.gzPerdotListBean</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

</managed-bean>

<navigation-rule>

<from-view-id>*</from-view-id>

<navigation-case>

<description>go to perdotList</description>

<from-outcome>OK</from-outcome>

<to-view-id>/perdotList.jsp</to-view-id>

</navigation-case>

<navigation-case>

<from-outcome>NO</from-outcome>

<to-view-id>/failue.jsp</to-view-id>

</navigation-case>

</navigation-rule>

</faces-config>

applicationcontext.xml

<beans>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName"><value>net.sourceforge.jtds.jdbc.Driver</value></property>

<property name="url"><value>jdbc:jtds:sqlserver://192.168.60.214:1433/jobcn_boss_Fn</value></property>

<property name="username"><value>sa</value></property>

<property name="password"><value>develop</value></property>

</bean>

<!-- Spring Data Access Exception Translator Defintion -->

<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">

<property name="dataSource"><ref bean="dataSource"/></property>

</bean>

<!-- Hibernate Session Factory Defintion -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">

<property name="mappingResources">

<list>

</list>

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>

<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>

</props>

</property>

<property name="dataSource">

<ref bean="dataSource"/>

</property>

</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">

<property name="sessionFactory"><ref local="sessionFactory"/></property>

</bean>

<bean id="gzperdotdao" class="jobcn.model.dao.jdbc.gzPerdotDaoImpl">

<property name="dataSource"><ref bean="dataSource"/></property>

</bean>

<bean id="gzperdotService" class="jobcn.model.service.impl.gzPerdotServiceImpl">

<property name="gzperdotdao"><ref local="gzperdotdao"/></property>

</bean>

<bean id="testService" class="jobcn.model.service.impl.gzPerdotServiceImpl">

<property name="gzperdotdao"><ref local="gzperdotdao"/></property>

</bean>

</beans>

猜你喜欢