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

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

学习了:http://blog.csdn.net/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) {
        }
}
原文地址:https://www.cnblogs.com/stono/p/7818123.html