JSF2.0 与Spring 3.0 集成

本文介绍如何在JSF环境中集成Spring框架,包括web.xml和Faces-config.xml的配置细节,以及Spring配置文件示例和一个注入Spring bean的JSF bean示例。
同以前的JSF1.2与Spring2.5集成类似,只是有一些类名的变化。

web.xml 代码如下:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>


Faces-config.xml中加入:


<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
JSF1.2和1.2以前是加入

<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>


Spring 的配置文件就正常配置就可以了。

ApplicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="WEB-INF/jdbc.properties" /> </bean>
-->
<!-- hibernate sessionFactory -->
<context:annotation-config/>
<context:component-scan base-package="cn.xiangyunsoft" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="hibernateProperties" value="classpath:hibernate.properties" />
<property name="configLocations">
<list>
<!-- 使用hibernate.cfg.xml配置文件 -->
<value>classpath:hibernate.cfg.xml
</value>
</list>
</property>
</bean>
<!-- 配置事务管理 -->
<!-- 事务通知类 -->
<!--
<bean id="profiler"
class="cn.xiangyunsoft.business.service.SimpleProfiler"> order
值可以决定通知的先后顺序 ,与后面的order的值的大小,决定了是先通知再执行,还是先执行再通知 <property
name="order" value="2" /> </bean>
-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<aop:config>
<!-- 此处的IService 是表示对所有实现IService接口的类管理事务 -->
<aop:advisor
pointcut="execution(* cn.xiangyunsoft.*.service..*ServiceImpl.*(..))"
advice-ref="txAdvice" />
<!--
加入之后事务不起作用> <aop:aspect id="profilingAspect" ref="profiler">
<aop:pointcut id="serviceMethodWithReturnValue"
expression="execution(*
cn.xiangyunsoft.*.service..*ServiceImpl.*(..))" />
<aop:after-throwing method="profile"
pointcut-ref="serviceMethodWithReturnValue" /> </aop:aspect
-->
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics -->
<tx:attributes>
<!-- 以get、find、load开头的方法是只读事务 -->
<tx:method name="*" read-only="true" />
<!--<tx:method name="find*" read-only="true" />-->
<!--<tx:method name="load*" read-only="true" />-->
<!-- 其他方法是默认,事务隔离级别为:保证一个事务修改的数据提交后才能被另外一个事务读取 -->
<tx:method name="save*" isolation="REPEATABLE_READ"
propagation="REQUIRED" />
<tx:method name="delete*" isolation="REPEATABLE_READ"
propagation="REQUIRED" />

</tx:attributes>
</tx:advice>
</beans>


一个注入Spring bean 的 JSF bean 代码如下:


@ManagedBean(name = ClassItemBean.NAME)
public class ClassItemBean {

public static final String NAME = "classItemBean";

/*
*在spring 中配置的service.
*/
@ManagedProperty(name = "classItemService", value = "#{classItemService}")
private ClassItemService classItemService;

public void setClassItemService(ClassItemService classItemService) {
this.classItemService = classItemService;
}

public String hello() {
System.out.println("hello." + classItemService);
Object obj = classItemService.get(ClassItem.class, "01");
System.out.println("obj = " + obj);
return null;
}
}
智慧医药系统(smart-medicine)是一款采用SpringBoot架构构建的Java Web应用程序。其界面设计简洁而富有现代感,核心特色在于融合了当前前沿的生成式人工智能技术——具体接入了阿里云的通义千问大型语言模型,以此实现智能医疗咨询功能,从而增强系统的技术先进性实用价值。该系统主要定位为医学知识查询辅助学习平台,整体功能结构清晰、易于掌握,既适合编程初学者进行技术学习,也可作为院校课程设计或毕业项目的参考实现。 中医舌诊作为传统医学的重要诊断手段,依据舌象的颜色、形状及苔质等特征来辨析生理状况病理变化。近年来,随着计算科学的进步,人工智能技术逐步渗透到这一传统领域,形成了跨学科的研究应用方向。所述的中医舌诊系统正是这一方向的实践产物,它运用AI算法对舌象进行自动化分析。系统以SpringBoot为基础框架,该框架依托Java语言,致力于简化Spring应用程序的初始化开发流程,其突出优势在于能高效构建独立、可投入生产的应用,尤其契合微服务架构云原生环境,大幅降低了开发者在配置方面的负担。 系统中整合的通义千问大语言模型属于生成式人工智能范畴,通过海量数据训练获得模拟人类语言的能力,可在限定领域内生成连贯文本,为用户提供近似专业医生的交互式咨询。该技术的引入有助于提升诊断过程的自动化水平结果一致性。 在设计体验层面,本系统强调逻辑明晰操作简便,旨在降低用户的学习门槛,尤其适合中医知识的入门教学。整体交互模式接近百科全书式查询,功能模块精炼聚焦,因而非常适用于教育场景,例如学术项目展示或毕业设计答辩。通过直观的实践界面,使用者能够更深入地理解中医舌诊的理论方法。 此外,系统界面遵循简约大气的设计原则,兼顾视觉美感交互流畅性,以提升用户的专注度使用意愿。结合AI的数据处理能力,系统可实现对舌象特征的快速提取实时分析,这不仅为传统诊断方法增添了客观量化维度,也拓展了中医知识传播的途径。借助网络平台,该系统能够突破地域限制,使更多用户便捷地获取专业化的中医健康参考,从而推动传统医学在现代社会的应用普及。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
【掺铒光纤放大器(EDFA)模型】掺铒光纤放大器(EDFA)分析模型的模拟研究(Matlab代码实现)内容概要:本文介绍了掺铒光纤放大器(EDFA)分析模型的模拟研究,并提供了基于Matlab的代码实现方案。通过对EDFA的工作原理、增益特性、噪声系数等关键性能指标进行数学建模仿真分析,帮助研究人员深入理解其在光通信系统中的作用机制。文档还列举了多个相关科研方向的技术支持内容,涵盖智能优化算法、路径规划、无人机应用、通信信号处理、电力系统管理等多个领域,展示了Matlab在科学研究工程仿真中的广泛应用能力。此外,文中附带网盘链接,便于获取完整的代码资源开发工具包。; 适合人群:具备一定光学通信或电子信息背景,熟悉Matlab编程,从事科研或工程仿真的研究生、高校教师及技术研发人员。; 使用场景及目标:①用于光通信系统中EDFA性能的理论分析仿真验证;②支持科研人员快速构建和测试EDFA模型,提升研究效率;③为教学实验、毕业设计及学术论文复现提供可靠的技术参考代码基础。; 阅读建议:建议读者结合光通信基础知识,按照文档结构逐步运行并调试Matlab代码,重点关注模型参数设置仿真结果分析,同时可利用提供的网盘资源拓展学习其他相关课题,深化对系统级仿真的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值