- 浏览: 514930 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (563)
- 工作经验 (12)
- 数据库 (13)
- Servlet (10)
- Struts2 (1)
- Spring (25)
- Eclipse (5)
- Hibernate (5)
- Eclips (8)
- HTTP (7)
- J2EE (21)
- EHcache (1)
- HTML (11)
- 工具插件使用 (20)
- JPA (2)
- 杂谈 (17)
- 数据结构与算法 (3)
- Cloud Foundry (1)
- 安全 (10)
- J2SE (57)
- SQL (9)
- DB2 (6)
- 操作系统 (2)
- 设计模式 (1)
- 版本代码管理工具 (13)
- 面试 (10)
- 代码规范 (3)
- Tomcat (12)
- Ajax (5)
- 异常总结 (11)
- REST (2)
- 云 (2)
- RMI (3)
- SOA (1)
- Oracle (12)
- Javascript (20)
- jquery (7)
- JSP自定义标签 (2)
- 电脑知识 (5)
- 浏览器 (3)
- 正则表达式 (3)
- 建站解决问题 (38)
- 数据库设计 (3)
- git (16)
- log4j (1)
- 每天100行代码 (1)
- socket (0)
- java设计模式 耿祥义著 (0)
- Maven (14)
- ibatis (7)
- bug整理 (2)
- 邮件服务器 (8)
- Linux (32)
- TCP/IP协议 (5)
- java多线程并发 (7)
- IO (1)
- 网页小工具 (2)
- Flash (2)
- 爬虫 (1)
- CSS (6)
- JSON (1)
- 触发器 (1)
- java并发 (12)
- ajaxfileupload (1)
- js验证 (1)
- discuz (2)
- Mysql (14)
- jvm (2)
- MyBatis (10)
- POI (1)
- 金融 (1)
- VMWare (0)
- Redis (4)
- 性能测试 (2)
- PostgreSQL (1)
- 分布式 (2)
- Easy UI (1)
- C (1)
- 加密 (6)
- Node.js (1)
- 事务 (2)
- zookeeper (3)
- Spring MVC (2)
- 动态代理 (3)
- 日志 (2)
- 微信公众号 (2)
- IDEA (1)
- 保存他人遇到的问题 (1)
- webservice (11)
- memcached (3)
- nginx (6)
- 抓包 (1)
- java规范 (1)
- dubbo (3)
- xwiki (1)
- quartz (2)
- 数字证书 (1)
- spi (1)
- 学习编程 (6)
- dom4j (1)
- 计算机系统知识 (2)
- JAVA系统知识 (1)
- rpcf (1)
- 单元测试 (2)
- php (1)
- 内存泄漏cpu100%outofmemery (5)
- zero_copy (2)
- mac (3)
- hive (3)
- 分享资料整理 (0)
- 计算机网络 (1)
- 编写操作系统 (1)
- springboot (1)
最新评论
-
masuweng:
亦论一次OutOfMemoryError的定位与解错 -
变脸小伙:
引用[color=red][/color]百度推广中运用的技术 ...
Spring 3 mvc中返回pdf,json,xml等不同的view -
Vanillva:
不同之处是什么??
Mybatis中的like查询 -
thrillerzw:
转了。做个有理想的程序员
有理想的程序员必须知道的15件事 -
liujunhui1988:
觉得很有概括力
15 个必须知道的 Java 面试问题(2年工作经验)
源:http://techdive.in/spring/spring-refresh-application-context
评:
Submitted by arunraj on Sun, 07/18/2010 - 14:59
In this section, we will discuss about how to reload an application context in Spring.
In many scenarios, you may require to reload the entire application context in Spring. But how to do it? There is actually an easy way to do. Have a look at the following code.
ApplicationContext ctx = new FileSystemXmlApplicationContext("Application-context.xml");
...
// Your application code here
...
((ConfigurableApplicationContext)ctx).refresh();
Take a closer look at the last line, which type casts Application Context in to Configurable Application Context class part and then calls its refresh method. At this point in your application the entire application context (all the beans in Application-context.xml) will be reloaded or recreated.
This is the simple way to reload the context without restarting the web server.
-------------
源:http://www.4byte.cn/question/1884180/is-spring-application-context-reloading-via-configurableapplicationcontext-refresh-considered-bad-practice.html
评:
We have a Spring application that is hosted on a shared tomcat instance.
Sometimes we have to reload the spring application context but don't want to restart the Tomcat server, because other application's are hosted there as well.
Is refreshing springs application context via
((ConfigurableApplicationContext)applicationContext).refresh();
considered bad practice?
What alternatives do I have?
Best Answer
A few issues that might arise -
Firstly, refresh() should destroy all beans currently living in the context (singletons etc) and recreate them, so any bootstrapping that might happen will happen again (stuff you put in InitializingBean beans etc). This is more of an issue for you, to make sure that all initializing code you've written is safe to be executed again.
Another thing to keep an eye on is how a refresh will affect the permanent memory generation (permgen). Since spring can (and will) proxy classes and create on-the-fly runtime-classes, this may prove to be a resource-leak since the bean-factory will probably create new runtime-classes when it refreshed the context.
评:
Submitted by arunraj on Sun, 07/18/2010 - 14:59
In this section, we will discuss about how to reload an application context in Spring.
In many scenarios, you may require to reload the entire application context in Spring. But how to do it? There is actually an easy way to do. Have a look at the following code.
ApplicationContext ctx = new FileSystemXmlApplicationContext("Application-context.xml");
...
// Your application code here
...
((ConfigurableApplicationContext)ctx).refresh();
Take a closer look at the last line, which type casts Application Context in to Configurable Application Context class part and then calls its refresh method. At this point in your application the entire application context (all the beans in Application-context.xml) will be reloaded or recreated.
This is the simple way to reload the context without restarting the web server.
-------------
源:http://www.4byte.cn/question/1884180/is-spring-application-context-reloading-via-configurableapplicationcontext-refresh-considered-bad-practice.html
评:
We have a Spring application that is hosted on a shared tomcat instance.
Sometimes we have to reload the spring application context but don't want to restart the Tomcat server, because other application's are hosted there as well.
Is refreshing springs application context via
((ConfigurableApplicationContext)applicationContext).refresh();
considered bad practice?
What alternatives do I have?
Best Answer
A few issues that might arise -
Firstly, refresh() should destroy all beans currently living in the context (singletons etc) and recreate them, so any bootstrapping that might happen will happen again (stuff you put in InitializingBean beans etc). This is more of an issue for you, to make sure that all initializing code you've written is safe to be executed again.
Another thing to keep an eye on is how a refresh will affect the permanent memory generation (permgen). Since spring can (and will) proxy classes and create on-the-fly runtime-classes, this may prove to be a resource-leak since the bean-factory will probably create new runtime-classes when it refreshed the context.
发表评论
-
使用Spring+Junit+Mockito做代码自测
2019-05-29 15:27 510源:https://blog.csdn.net/z19917 ... -
在同一个类中调用另一个方法没有触发 Spring AOP 的问题
2017-08-24 17:22 577源:https://segmentfault.com/a/11 ... -
Spring Transaction属性之Propagation
2016-08-10 17:09 548源:http://blog.csdn.net/kiwi_cod ... -
循环依赖检测方法 spring源码方法
2016-07-06 18:58 1169场景:checkForAliasCircle(name, al ... -
Spring的Quartz定时器同一时刻重复执行二次的问题解决
2016-03-11 18:27 1005源:http://www.linuxidc.com/Linux ... -
spring factory-method
2016-03-01 11:22 488源:http://blog.sina.com.cn/s/blo ... -
spring中lazy-init详解
2016-02-29 17:01 780源:http://blog.csdn.net/fhx0 ... -
spring context 扫描与 mvc扫描类 区分开包
2015-07-15 13:23 6111.applicationContext.xml <!- ... -
Filter中注入spring
2015-07-09 10:45 512源:http://zy116494718.iteye.com/ ... -
获取spring的ApplicationContext几种方式
2015-06-24 15:35 699源:http://blog.sina.com.cn/s/blo ... -
spring获取webapplicationcontext,applicationcontext几种方法详解
2015-04-02 16:38 467源:http://www.blogjava.net/Todd/ ... -
Spring+Mybatis整合事务不起作用之解决方案汇总
2014-12-29 21:36 1354源:http://blog.csdn.net/walkerjo ... -
context:component-scan扫描使用上的容易忽略的use-default-filters
2014-12-29 21:29 452源:http://jinnianshilongnian.ite ... -
Spring线程池开发实战
2014-12-12 10:44 499源:http://blog.csdn.net/chszs/ar ... -
AOP生成代码有三种可能方式
2014-05-11 21:24 449源:http://blog.csdn.net/zuyi532/ ... -
Spring 3 mvc中返回pdf,json,xml等不同的view
2014-05-09 12:11 1041源:http://jackyrong.iteye.com/bl ... -
使用Spring MVC统一异常处理实战
2014-05-04 00:00 525源:http://cgs1999.iteye.com/blog ... -
spring配置文件异常
2013-11-26 10:53 906源:http://wodar.iteye.com/blog/ ... -
自己对spring ioc的理解
2013-07-14 11:59 1075此时心情:有时候工作的很努力,很认真也会被辞退,被小外包公 ... -
spring 定时器配置
2013-03-20 15:09 1097源:http://blog.csdn.net/cl61917 ...
相关推荐
在 refresh 方法中,Spring 会做一些准备工作,如创建 BeanFactory、注册 BeanFactoryPostProcessor 等,只有等这些准备工作做好以后才去开始 Spring Context 的启动。 通过这些内容,我们可以更好地理解 Spring 中...
Spring refresh()方法相关异常解析 Spring 是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring 是一个轻量级的 Java 开发框架,由...
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@c1f10e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@15e234c ...
import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; import org.spring...
import org.springframework.context.annotation.Bean; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; ...
在Spring框架中,Context是Spring应用的核心容器,它负责管理所有Bean的生命周期和依赖注入。本文将深入探讨Spring Context的两种加载方式:基于XML配置和基于注解的配置。 首先,传统的Spring Context加载方式通常...
如果需要在不重启的情况下实时更新配置,可以考虑使用Spring Cloud Config Server或使用Spring Boot Actuator的`/refresh`端点来实现配置的热更新。 总结来说,Spring Boot通过`@Scheduled`注解提供了强大的定时...
- 初始化bean后处理器和`ApplicationListener`。 - 预初始化一些其他的bean,例如`@PostConstruct`注解的方法会被调用。 - 最后,设置`WebApplicationContext`为“活跃”状态。 这个过程可以通过时序图来形象地表示...
String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class.getName() + ".ROOT"; …… //对WebApplicationContext来说,需要得到Web容器的ServletContext ServletContext ...
- 可以通过实现`org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor`接口来自定义属性绑定逻辑。 10. **配置绑定的生命周期** - 当Spring应用启动时,`@...
`@SpringBootApplication` 是Spring Boot应用程序的核心注解,它由三个关键注解组成: 1. **@Configuration**:表示这是一个配置类,可以替代XML配置文件。 2. **@EnableAutoConfiguration**:开启自动配置功能,这...
在上述代码中,我们使用了`@RefreshScope`注解,这意味着当调用`/refresh`端点时,`Application`类中的`name`属性将被重新加载,从而反映出Git仓库中最新的配置值。 总结一下,Spring Cloud Config 提供了强大的...
context.refresh(); // 刷新上下文 DemoBean demoBean = context.getBean(DemoBean.class); System.out.println(demoBean.getContent()); context.close(); } } ``` ### 2. Spring Boot 中的 Profile 使用 ...
`ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE`常量用于在`ServletContext`中存储根`WebApplicationContext`的引用,这样Web应用的其他部分就可以找到并使用这个容器。 `XmlWebApplicationContext`是`...
启动应用时,Spring Boot会自动加载`application.properties`或`application.yml`,如果存在的话。另外,你也可以通过`--spring.config.location`命令行参数指定额外的配置文件位置。 ### 2. 配置文件加载顺序 ...
context.refresh(); } ``` 3. **默认Profile** 当没有明确指定`profile`时,Spring会使用`default`作为默认`profile`。可以通过`@Profile("default")`注解创建默认配置,当没有其他`profile`被激活时,这个`...
在application.yml文件中,我们需要配置OAuth2客户端的信息: server: port: 8082 servlet: context-path: /ui session: cookie: name: UISESSION security: basic: enabled: false oauth2: client: ...
例如,`ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE`常量用于在`ServletContext`中存储根上下文,使得在整个Web应用程序中可以共享该上下文。 当Web应用程序启动时,Spring通常会使用`XmlWebApplicationContext`作为...
- **Bootstrap Context**:不同于普通的Spring应用上下文,客户端在启动时会首先创建Bootstrap Context来获取配置服务器的地址,然后再创建常规的应用上下文。 - **配置加载**:客户端通过`@RefreshScope`注解实现...
- Spring Boot应用中,可以使用Actuator的 `/shutdown` 和 `/refresh` 端点,分别用于安全地关闭和刷新Quartz调度器。 这个"quartz-demo.zip"中的项目应该包含了上述所有步骤的示例代码,通过查看和运行这些代码,...