Metrics
0
Watch 7 Star 19 Fork 7

苦涩的决断 / jfinal-plusJava

Sign up for free
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
jfinal 增强 spread retract

Clone or download
README.md 1.69 KB
Copy Edit Web IDE Raw Blame History

#jfinal-plus-spring 作用于 spring 和 jfinal ioc plugin。 支持 ioc @Inject @Value @Autowired ioc @Resource

#使用 Maven

	<dependency>
	  <groupId>com.jfinalplus</groupId>
	  <artifactId>jfinal-plus-spring</artifactId>
	  <version>x.x.x</version>
	</dependency>

1、JFinalConfig 配置

public class HelloJFinalConfig extends JFinalConfig {

	@Autowired
	private ApplicationContext ctx;
	
	...
	@Override
	public void configConstant(Constants me) {
		...
		// 需要 web.xml 配置 org.springframework.web.context.ContextLoaderListener
		IocKit.processJFinalConfig(this);// or IocKit.processJFinalConfig(this,ctx);
		...
	}
	
	@Override
	public void configPlugin(Plugins me) {
		me.add(new SpringPlugin(ctx));
	}
	...
}

2、创建 Interceptor (由于 2.0之前和2.0 的版本有区别所用不提供 Ioc 对象,需自己创建)如:

// jfinal v2.0 之前
public class IocInterceptor implements Interceptor {

	@Override
	public void intercept(ActionInvocation ai) {
		IocKit.invokeForProcessInjection(ai);
	}
}

3、Controller

@Before(IocInterceptor.class)
public class HelloController extends Controller {
	
	// @Autowired 
	ApplicationContext ctx;

	@Autowired
	public void setApplicationContext(ApplicationContext ctx) {
		System.out.println("HelloController attr[ApplicationContext] 已注入。。");
	}
}

4、更多支持

Comment ( 0 )

You need to Sign in for post a comment

Help Search

Gitee_you_jiang_zheng_wen Zheng_wen_close