首页 > 其他 > 详细

静态工具类中使用注解注入service(静态方法调用有注解的非静态方法)

时间:2017-03-24 11:43:20      阅读:822      评论:0      收藏:0      [点我收藏+]

原文转载:http://blog.csdn.net/p793049488/article/details/37819121

解决方案如下:

/**
*
*/
package cn.common.util;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



@Component
public class Utils {


@Autowired
private Service service;
private static Utils utils;

public void setUserInfo(Service service) {
this.service = service;
}

@PostConstruct
public void init() {
  utils = this;
  utils.service = this.service;

}


public static void insertOpeLog(HttpServletRequest req, String str) {

  ServiceBean bean =new ServiceBean();
  utils.service.save(bean); //调用方法

}

}

静态工具类中使用注解注入service(静态方法调用有注解的非静态方法)

原文:http://www.cnblogs.com/xiaohaizhuimeng/p/6610689.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!