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 ...
随机推荐
- CentOS使用systemctl daemon-reload报错Error getting authority: Error initializing authority: Error calling StartServiceByName for org.freedesktop.PolicyKit1: Timeout was reached (g-io-error-quark, 24)解决办法
CentOS修改了系统启动文件后需要重载报错 systemctl daemon-reload Error getting authority: Error initializing authority ...
- ML.NET 0.10特性简介
IDataView被单独作为一个类库包 IDataView组件为表格式数据提供了非常高效的处理方式,尤其是用于机器学习和高级分析应用.它被设计为可以高效地处理高维数据和大型数据集.并且也适合处理属于更 ...
- win10系统激活
我们常常使用一些激活工具来激活,效果可能比较差.比如我激活win10教育版,下载了很多软件无论如何都不能激活.但是使用命令行很容易就激活了. 1. 2.在命令提示符中依次输入: slmgr.vbs / ...
- MySQL 添加索引,删除索引及其用法
一.索引的作用 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,所以查询语句的优化显然是重中之重. 在数据 ...
- 13.0-uC/OS-III上下文切换
1.当uC/OS-III转向执行另一个任务的时候,它保存了当前任务的CPU寄存器到堆栈.并从新任务的的堆栈中CPU寄存器载入CPU.这个过程叫做上下文切换. 上下文切换需要一些开支. CPU的寄存器越 ...
- Jmeter学习之-从数据库取出数据并且校验数据是否准确
https://www.cnblogs.com/wuyonghuan/p/7479582.html 应用场景:调用某个接口像数据库中插入数据,需要在接口调用完成后查看数据更新或插入的数据是否正确的时候 ...
- Python静态方法(staticmethod)和类方法(classmthod)
Python静态方法(staticmethod)和类方法(classmthod)翻了翻之前的笔记,也刚好看到一篇不错的blog,关于静态方法和类方法的,方便以后查阅,就写在这里了,废话不多说,直接上代 ...
- Python3使用AES加密的库函数PyCrypto、PyCryptodome
我们在网上查看Python爬虫教程的时候,细心的朋友会发现:很多网站为了降低服务器的请求压力都做了各式各样的反爬策略,浏览器通过http post请求服务器端数据时,传输的data字段很多都是经过加密 ...
- 12.C# 接口和抽象类的区别
1.抽象类 声明方法的存在而不去实现它的类叫做抽象类,抽象类用abstract关键字声明.抽象类主要用来规定某些类的基本特征,继承它的子类必须实现抽象类的抽象成员,否则这个子类也为抽象类. publi ...
- redis安装及错误排查
安装: 1.cd /usr/redis //redis目录作为安装目录,没有自行创建 2.tar xzf redis-4.0.6.tar.gz 3. cd redis-4.0.6 4.make ...