开发者社区> 问答> 正文

spring IoC和JFinal的集成

我按照文档配置SpringPlugin,但是我在一些Interceptor和Listener上配置@Before(IocInterceptor.class)后没有自动注入。把IocInterceptor配置成全局的也是一样。

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:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
 
    <context:annotation-config/>
 
</beans>


Interceptor:

@Before(IocInterceptor.class)
public class AccessLogInterceptor implements Interceptor
{
  @Inject.BY_NAME
  private SessionService sessionService;
   
  @Override
  public void intercept(ActionInvocation ai)
  {
    ...
    sessionService.updateSession(session, url);
    ai.invoke();
  }
}

谁知道有没有不用SpringPlugin,直接用Spring的方法?

尝试了配置org.springframework.web.context.ContextLoaderListener没有成功。

展开
收起
a123456678 2016-03-16 17:59:02 3021 0
1 条回答
写回答
取消 提交回答
  • 将 IocInterceptor 这个拦截器配置成全局的,或者配置在 Controller 上,然后使用 @Inject.BY_NAME、@Inject.BY_TYPE进行注入配置

    楼主代码中将 IocInterceptor 配置在了 Interceptor 之上,这肯定不会起作用,拦截器只能应用在 Controller 之上

    2019-07-17 19:04:16
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载