Spring Bean Reload Problem Resolution

Source: Internet
Author: User

Background:

1, Tomcat project start-up is relatively slow, will lead to a long period of time can not provide services to the outside.

2, the number of servers is more, the update of one operation will take a long time.


Describe:

Make adjustments to the system framework, turn frequently updated features into spring jar packages, and place them on a Web site, and then the system deployed on Tomcat automatically requests the latest spring jar packages from the Web site.

Note: This is not implemented with Mbean, given the performance of the system.


Implementing Critical Code:

1, JAR Package resolution

Myclassloader = new URLClassLoader (new url[] {url},context.getclassloader ());

Thread.CurrentThread (). Setcontextclassloader (Myclassloader);


2. Use the new JAR package

Defaultlistablebeanfactory defaultlistablebeanfactory = (defaultlistablebeanfactory) Context.getautowirecapablebeanfactory ();

Defaultlistablebeanfactory.setbeanclassloader (Myclassloader);

3, the Bean loaded initialization

Simplebeandefinitionregistry Registry = new Simplebeandefinitionregistry ();

Xmlbeandefinitionreaderreader =new Xmlbeandefinitionreader ((beandefinitionregistry) registry);

Reader.loadbeandefinitions (R);

4. Bean Update

String [] beannames = Registry.getbeandefinitionnames ();

for (String n:beannames) {

Defaultlistablebeanfactory.registerbeandefinition (N,registry.getbeandefinition (n));

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.