Simple use of ApplicationContext for testing

Source: Internet
Author: User

First: Only one XML file
public static void main(String[] args) {        ApplicationContext ac = null;        try {            ac = new ClassPathXmlApplicationContext("beans.xml");            //ac = new ClassPathXmlApplicationContext("classpath:beans.xml");        } catch (Exception e) {            LOGGER.error("spring启动错误", e);        }        Account test3 = (autoAccount) ac.getBean("account");        test3.account();}
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>13 1
public static void Main (string[] args) {
2
  ApplicationContext ac = null;
3
  try {
4
  ac = new Classpathxmlapplicationcontext ("Beans.xml");
5
  //ac = new Classpathxmlapplicationcontext ("Classpath:beans.xml");
6
  } catch (Exception e) {
7
  logger.error ("Spring start Error", E);
8
  }
9
10
11
Account  test3 = (autoaccount) Ac.getbean ("account");
12
  Test3.account ();
13
}

The second type: There are more than two files, and write out the name of each file
    public static void main(String[] args) {        ApplicationContext ac = null;        try {            ac = new ClassPathXmlApplicationContext(new String[] {"classpath:beans.xml", "classpath:quartz.xml"});        } catch (Exception e) {            LOGGER.error("spring启动错误", e);        }        Account test3 = (autoAccount) ac.getBean("account");        test3.account();    }
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>13 1
Public  static void Main (string[] args) {
2
  ApplicationContext ac = null;
3
  try {
4
  ac = new Classpathxmlapplicationcontext (new string[] {"Classpath:beans.xml", "Classpath:quartz.xml"});
5
  } catch (Exception e) {
6
  logger.error ("Spring start Error", E);
7
  }
8
9
10
Account  test3 = (autoaccount) Ac.getbean ("account");
11
  Test3.account ();
12
13
  }

The third type: wildcard characters
public static void main(String[] args) {        ApplicationContext ac = null;        try {            ac = new ClassPathXmlApplicationContext("classpath:/*.xml");        } catch (Exception e) {            LOGGER.error("spring启动错误", e);        }        Account test3 = (autoAccount) ac.getBean("account");        test3.account();}
<textarea spellcheck="false" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none" tabindex="0" readonly=""></textarea>12 1
{
2
  ApplicationContext ac = null;
3
  try {
4
  ac = new Classpathxmlapplicationcontext ("Classpath:/*.xml");
5
  } catch (Exception e) {
6
  logger.error ("Spring start Error", E);
7
  }
8
9
10
Account  test3 = (autoaccount) Ac.getbean ("account");
11
  Test3.account ();
12
}


Simple use of ApplicationContext for testing

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.