一、applicationContext.xml配置bean

 <bean id="sensitiveWordInitUtil" class ="com.hx.dazibo.front.util.SensitiveWordInitUtil" scope="singleton"
init-method="initKeyWord"> <property name="xmlFile"> <value>classpath:sensitive-word.xml</value> </property> </bean>

说明:bean:
            class 为需要执行的类
            init-method对应该类需要执行的方法
            property:
            name 对应类中需要注入的属性对象(必须设置set方法,否则无法注入)
            value 为注入的值

二、执行的类SensitiveWordInitUtil

public class SensitiveWordInitUtil {
public File xmlFile;// 敏感词库XML文件 public File getXmlFile() {
return xmlFile;
}
public void setXmlFile(File xmlFile) {
this.xmlFile = xmlFile;
} /**
* 初始化方法
*
* @return
*/
public Map initKeyWord() {
try {
//这里编写初始化业务 } catch (Exception e) {
e.printStackTrace();
}
return sensitiveWordMap;
}
}

Spring项目启动时执行初始化方法的更多相关文章

  1. 在web项目启动时执行某个方法

    在web项目中有很多时候需要在项目启动时就执行一些方法,而且只需要执行一次,比如:加载解析自定义的配置文件.初始化数据库信息等等,在项目启动时就直接执行一些方法,可以减少很多繁琐的操作. 在工作中遇到 ...

  2. Spring在Web容器启动时执行初始化方法

    需求:在tomcat启动时开启一个定时任务. 想法:容器启动时执行方法,最容易想到的就是servlet中可以配置load-on-startup,设置一个正整数也就可以随容器一起启动. 问题:上面的方法 ...

  3. spring 在web容器启动时执行初始化方法

    开发框架:spingMVC+myBatis 解决方案:给web容器添加一个Listener类,在容器启动的时候执行Listener的“初始化”方法,在这个初始化方法中执行查询数据库的所有操作,然后将数 ...

  4. spring注解之@PostConstruct在项目启动时执行指定方法

    一.注解解释 Spring的@PostConstruct注解在方法上,表示此方法是在Spring实例化该Bean之后马上执行此方法,之后才会去实例化其他Bean,并且一个Bean中@PostConst ...

  5. Spring Boot学习--项目启动时执行特定方法

    Springboot给我们提供了两种"开机启动"某些方法的方式:ApplicationRunner和CommandLineRunner. 这两种方法提供的目的是为了满足,在项目启动 ...

  6. Java项目启动时执行指定方法的几种方式

    很多时候我们都会碰到需要在程序启动时去执行的方法,比如说去读取某个配置,预加载缓存,定时任务的初始化等.这里给出几种解决方案供大家参考. 1. 使用@PostConstruct注解 这个注解呢,可以在 ...

  7. SpringBoot项目启动时执行初始化操作

    SpringBooot中的CommandLineRunner接口会在所有Spring Beans初始化之后,SpringApplication.run()之前执行. 1.添加pom引用 <?xm ...

  8. spring boot 启动后执行初始化方法

    http://blog.csdn.net/catoop/article/details/50501710 1.创建实现接口 CommandLineRunner 的类 package org.sprin ...

  9. java项目启动时执行指定方法

    想到的就是监听步骤如下: 1.配置web.xml <listener> <listener-class>com.listener.InitListener</listen ...

随机推荐

  1. notepad++必读

    #预备知识Ctrl: control 控制键 Ctrl + TabAlt:alter 改变键(换码键) Alt + TabShift: shift 换挡键(切换键) Ctrl + Shift + Ta ...

  2. iOS:后台定位并实时向服务器发送位置

    第一步:开启后台模式,选中定位,选择project --> capabilities-->Backgorund Modes --> Location updates 如图: 第二步: ...

  3. 构建LINUX下的入侵检测系统——LIDS 系统管理命令--vlock

    构建LINUX下的入侵检测系统——LIDS   系统管理命令--vlock http://blog.chinaunix.net/uid-306663-id-2440200.html LIDS官方网站: ...

  4. Cache封装类

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...

  5. 使用 jQuery Deferred 和 Promise 创建响应式应用程序

    这篇文章,我们一起探索一下 JavaScript 中的 Deferred 和 Promise 的概念,它们是 JavaScript 工具包(如Dojo和MochiKit)中非常重要的一个功能,最近也首 ...

  6. CentOS6.5 安装HAProxy 1.5.20

    [在CentOS下安装haproxy] sudo yum install haproxy 编辑配置文件 vim /etc/haproxy/haproxy.cfg #------------------ ...

  7. Some settings of PostgreSQL

    Here are some setting recommendations about checkpoints, some values to set in postgresql.conf. A ch ...

  8. 通达信:显示K线图日期

    INFO_A:=STRCAT('INFO_A=', STRCAT(CON2STR(REF(MONTH, REF_BAR_A), 0), STRCAT('-', STRCAT(CON2STR(REF(D ...

  9. :“boost/serialization/string.hpp”: No such file or directory 错误

    主要原因是没有安装和配置boost库. 解决:http://www.programlife.net/boost-compile-and-config.html

  10. websotrm注册码

    webStorm : UserName:William ===== LICENSE BEGIN ===== 45550-12042010 00001SzFN0n1bPII7FnAxnt0DDOPJA ...