Jfinal集成Spring
JFinal框架也整合了spring框架,下面实现JFinal怎么去配置Spring框架。在JFinal中整合Spring使用到的类是SpringPlugin和IocInterceptor类
SpringIplugin类:
SpringPlugin 是作为 JFinal 的 Plugin 而存在的,所以使用时需要在 JFinalConfig 中配置SpringPlugin,以下是 Plugin 配置示例代码:
/**
* 配置插件
*/
@Override
public void configPlugin(Plugins me) {
//ConfigDBPluginHelper.configOraclePlugin(me);
//配置Spring挂件, 自动找spring包中所有的xml配置文件
me.add(new SpringPlugin("classpath*:spring/*.xml"));
}
配置SpringPlugin
以上设置默认spring配置xml在src/spring包下
如果设置sringPlugin的时候,没有设置路径
/**
* 配置插件
*/
@Override
public void configPlugin(Plugins me) {
//ConfigDBPluginHelper.configOraclePlugin(me);
//配置Spring挂件, 自动找spring包中所有的xml配置文件
me.add(new SpringPlugin());
}
无参数设置
SpringPlugin 将 自动去WebRoot/WEB-INF 目录下寻找 applicationContext.xml 作为配置文件进行初始化。
IocInterceptor类:
IocInterceptor 拦截 action 并对其进行依赖注入,以下是示例代码:
package com.demo.testSpring; import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.spring.IocInterceptor;
import com.jfinal.plugin.spring.Inject; @Before(IocInterceptor.class)
public class testSpringController extends Controller{ @Inject.BY_NAME
private Animal animal; public void test(){
animal.move();
animal.jump();
renderNull();
}
}
IocInterceptor
package com.demo.testSpring; public class Animal {
private String animalName; public void setAnimalName(String animalName) {
this.animalName = animalName;
} public void move(){
System.out.println(animalName+" move");
} public void jump(){
System.out.println(animalName+" jump");
}
}
依赖Animal类
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="animal" class="com.demo.testSpring.Animal">
<property name="animalName">
<value>dog</value>
</property>
</bean> </beans>
配置文件
需要的jar包
注:IocInterceptor可以设置为全局拦截器;
/**
* 配置全局拦截器
*/
public void configInterceptor(Interceptors me) {
me.add(new IocInterceptor());
}
设置为全局拦截器
如果在非Controller中的类中使用spring注入,不需要那么多注解,只需要在xml中配置即可。如下:
package com.demo.testSpring; public class Cat { private Animal animal; public void setAnimal(Animal animal) {
this.animal = animal;
} public void test(){
animal.move();
animal.jump();
}
}
Cat类
package com.demo.testSpring; import com.jfinal.core.Controller;
import com.jfinal.plugin.spring.Inject; public class testSpringController extends Controller{ @Inject.BY_NAME
private Cat cat; public void test(){ cat.test();
renderNull();
}
}
Controller
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <bean id="animal" class="com.demo.testSpring.Animal">
<property name="animalName">
<value>dog</value>
</property>
</bean> <bean id="cat" class="com.demo.testSpring.Cat">
<property name="animal">
<ref bean="animal"/>
</property>
</bean> </beans>
配置项
jfinal不提供自动注入功能,如autowared
Jfinal集成Spring的更多相关文章
- jfinal集成spring cxf做webservice服务
链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...
- MyBatis6:MyBatis集成Spring事物管理(下篇)
前言 前一篇文章<MyBatis5:MyBatis集成Spring事物管理(上篇)>复习了MyBatis的基本使用以及使用Spring管理MyBatis的事物的做法,本文的目的是在这个的基 ...
- CXF集成Spring实现webservice的发布与请求
CXF集成Spring实现webservice的发布(服务端) 目录结构: 主要代码: package com.cxf.spring.pojo; public class User { int id ...
- Dubbo集成Spring与Zookeeper实例
>>Dubbo最佳实践 使用Dubbo结合Zookeeper和Spring,是使用比较广泛的一种组合,下面参考官方文档,做个简单的示例,一步步搭建一个使用dubbo结合Zookeeper和 ...
- Thymeleaf 集成spring
Thymeleaf 集成spring 如需先了解Thymeleaf的单独使用,请参考<Thymeleaf模板引擎使用>一文. 依赖的jar包 Thymeleaf 已经集成了spring的3 ...
- 06_在web项目中集成Spring
在web项目中集成Spring 一.使用Servlet进行集成测试 1.直接在Servlet 加载Spring 配置文件 ApplicationContext applicationContext = ...
- Hibernate 检索查询的几种方式(HQL,QBC,本地SQL,集成Spring等)
1.非集成Spring hibernate的检索方式,主要有以下五种. 1.导航对象图检索方式.(根据已经加载的对象,导航到其他对象.) 2.OID检索方式.(按照对象的OID来检索对象.) 3.HQ ...
- SpringMVC 3.1集成Spring Security 3.1
这篇算是一个入门文章,昨天看见有网友提问,spring mvc集成spring security 的时候出错,揣测了一下问题木有解决.我就帮忙给搭建了一个集成框架他说可以,他告诉我这样的文章网上少.今 ...
- 【Spring】关于Boot应用中集成Spring Security你必须了解的那些事
Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...
随机推荐
- git使用记录_备忘
---恢复内容开始--- 一.将本地的文件上传到git 1.cd 本地文件目录 2.git init git init 命令使git命令可以管理当前的目录 3.git remote add origi ...
- myEclipse导入现成项目出现错误 【申明来源于网络】
myEclipse导入现成项目出现错误 [申明来源于网络] 原地址:http://blog.sina.com.cn/s/blog_6d7703400100znh6.html file–>impo ...
- Vue中computed,methods 和watch
Vue中的计算属性和方法属性 1.计算属性 computed 模版中可以使用表达式 <div id="example"> {{ message.split('').re ...
- C#中的double类型数据向SQL sqerver 存储与读取问题
1.存储 由于double类型在SQLsever中并没有对应数据,试过对应float.real类型,发现小数位都存在四舍五入的现象,目前我使用的是decimal类型,用此类型时个人觉得小数位数应该比自 ...
- js的字符串代码库及讲解
1.字符串操作 1.1去除字符串空格 元字符 : \s:空格或者空白等 ^ : 限定开始位置 => 本身不占位置 $ : 限定结束位置 => 本身不占位置 | : 或者 () : 分组代表 ...
- 百度的富文本编辑器UEditor批量添加图片自动加上宽度和高度的属性
若是没有对编辑器做任何配置直接添加图片的话,显示的html内容如下图所示:它会显示出原图片尺寸 所以必须要对图片的初始显示尺寸做控制:ueditor文件中找到image.js文件 在image.js中 ...
- spring--给配置文件.properties加密
11111111111编写类并继承PropertyPlaceholderConfigurer.java package com.xx.encryptDecrypt; import java.util. ...
- ZooKeeper之service discovery
Zookeeper整体介绍 ZooKeeper is a centralized service for maintaining configuration information, naming, ...
- solr6.5.1搜索引擎的部署
目录结构如下: 6.5.1版本的solr已经集成有jetty服务器(在server目录下),所以可以直接启动solr应用. 1.java环境配置好(这里不再累赘). 2.打开cmd,路径切换到bin目 ...
- repo 获取各个库的tag代码或者分支代码
关于mainfest.xml中的参数格式和说明,可以自己查阅,此处不详细写,我们知道project中的reversion可以指定分支,tag,commitid等,那么如何书写呢? 首先克隆mainfe ...