SpringMvc 系统启动时加载数据到内存中

本文介绍如何在SpringMVC系统启动时将数据加载到内存中,提供了两种实现方式:通过配置文件指定服务类并禁用懒加载,或者使用@Service注解配合@Lazy(false)。这两种方法都能确保在应用初始化阶段完成数据加载。

SpringMvc 系统启动时加载数据到内存中

学习了:http://blog.youkuaiyun.com/newstruts/article/details/18668269

https://www.cnblogs.com/zhengteng/p/5381910.html

http://xfxlch.iteye.com/blog/2048049

http://duanxuchu.iteye.com/blog/2181647

结论:

方案一:

<!--beans.xml中配置 扫描服务包 -->
<context:component-scan base-package="com.stono.service" />

package com.stono.service
@Service
@Lazy(false) // 注意这句
public class LoadDataService implements ServletContextAware {

    @Autowired
    TblMapper tblMapper;
    
    @Override
    public void setServletContext(ServletContext context) {

        }
}

 

方案二:

<!--在beans.xml 中进行配置-->
<bean id="loadDataService" class="com.stono.service.LoadDataService"   lazy-init="false">
</bean>

package com.stono.serivce

@Service // @Component // 写成@Component也可以
public class LoadDataService implements ServletContextAware {
    @Autowired
    TblMapper tblMapper;
        @Override
    public void setServletContext(ServletContext context) {
        }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值