@Autowired注解在非Controller中注入为null

1、配置文件(类文件所在的包)

<context:component-scan base-package="net.nblh.utils.common" />

2、类文件

关于@PostConstruct:被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。

@Component //申明为spring组件
public class GetSpeechRecognitionInfo {
@Autowired
private IConfDayService confdayService; // 静态初使化当前类
public static GetSpeechRecognitionInfo getSpeechRecognitionInfo;
//注解@PostConstruct,这样方法就会在Bean初始化之后被Spring容器执行
@PostConstruct
public void init() {
getSpeechRecognitionInfo = this;
} public static void syncDocument(String topicId) {
List<TopicFile> fileList = getSpeechRecognitionInfo.confdayService.getConfFileByIssue(topicId);//议题材料列表
}
}

java-普通类文件@Autowired自动注入为null的更多相关文章

  1. @Autowired自动注入失败

    新手注意的问题 package cn.ryq.web.controller; import cn.ryq.domain.company.Company;import cn.ryq.service.co ...

  2. Java虚拟机-类文件

    代码编译的结果从本地机器码转换为字节码,是存储格式发展的一小步,却是编程语言发展的一大步.计算机只认识0和1,所以我们的程序需要经过编译器翻译成由0和1组成的二进制格式才能由计算机执行.经过技术的发展 ...

  3. PHP 类文件的自动加载机制 __autoload()

    如果一个类在多个脚本中都需要使用,可以将一个类的定义代码,单独的封装到一个文件中,这种文件也叫作类文件,在需要的时候,将整个文件载入进来即可! PHP在执行的时候,如果发现需要一个类(只要是和这个类相 ...

  4. Spring 注解Autowired自动注入bean异常解决

      错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined ...

  5. ES6+转ES5(webpack+babel、指定多个js文件、自动注入)

    接续上篇ES6+转ES5,本篇将使用webpack和babel将多个不同目录下指定的多个ES6+语法的js文件编译为ES5,并将编译后的文件配置注入对应的html文件. 所需环境node.npm.设置 ...

  6. 解决 SpringMVC 非spring管理的工具类使用@Autowired注解注入DAO为null的问题

    在SpringMVC框架中,我们经常要使用@Autowired注解注入Service或者Mapper接口,我们也知道,在Controller层中注入service接口,在service层中注入其它的s ...

  7. 解决非controller使用@Autowired注解注入为null问题

    在SpringMVC框架中,我们经常要使用@Autowired注解注入Service或者Mapper接口,我们也知道,在controller层中注入service接口,在service层中注入其它的s ...

  8. SpringBoot中普通类无法通过@Autowired自动注入Service、dao等bean解决方法

    无法注入原因: 有的时候我们有一些类并不想注入Spring容器中,有Spring容器实例化,但是我们又想使用Spring容器中的一些对象,所以就只能借助工具类来获取了 工具类: package com ...

  9. 解决Spring Boot集成Shiro,配置类使用Autowired无法注入Bean问题

    如题,最近使用spring boot集成shiro,在shiroFilter要使用数据库动态给URL赋权限的时候,发现 @Autowired 注入的bean都是null,无法注入mapper.搜了半天 ...

随机推荐

  1. TensorFlow函数:tf.lin_space

    函数:tf.lin_space 别名: tf.lin_space tf.linspace lin_space( start, stop, num, name=None ) 参见指南:生成常量,序列和随 ...

  2. python中pass语句的作用是什么

    pass语句不会执行任何操作,一般作为占位符或者创建站位程序,whileFalse:pass.

  3. Collection集合复习方法回顾

    Collection集合方法: add()  //添加元素 remove()    //移除元素 size()                                     //返回集合长度 ...

  4. 2016ICPC-大连 A Simple Math Problem (数学)

    Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least Common ...

  5. Java编程中必须了解 十几个代码段

    向文件末尾添加内容 字符串有整型的相互转换 转字符串到日期 java.util.Date = java.text.DateFormat.getDateInstance().parse(date Str ...

  6. JAVA中关于对像的读写

    /** * 针对对象的文件读写 */ //导入包 import java.io.File; import java.io.FileInputStream; import java.io.FileNot ...

  7. CentOS6.x安装RabbitMQ

    一.安装依赖文件 yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ ...

  8. Windows在当前目录打开cmd

    /********************************************************************** * Windows在当前目录打开cmd * 说明: * ...

  9. [LeetCode&Python] Problem 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  10. xdoj-1319 求树上任意一点的最大距离----利用树的直径

    1 #include <bits/stdc++.h> using namespace std; ; vector < vector <int> > g(N); in ...