Enterprise Distribution Micro Service Cloud Springcloud springboot MyBatis (18) springboot which beans were injected at startup

Source: Internet
Author: User

Add in the program entry:

@SpringBootApplicationpublic class Springbootfirstapplication {public    static void Main (string[] args) {        Springapplication.run (Springbootfirstapplication.class, args);    }    @Bean public    Commandlinerunner Commandlinerunner (ApplicationContext ctx) {        return args, {            SYSTEM.OUT.PRINTLN ("Let's inspect the beans provided by Spring Boot:");            string[] Beannames = Ctx.getbeandefinitionnames ();            Arrays.sort (beannames);            for (String beanname:beannames) {                System.out.println (beanname);}}        ;}    }

  

Program output:

Let's inspect the beans provided by Spring Boot:basicerrorcontroller beannamehandlermapping beannameviewresolver charact Erencodingfilter Commandlinerunner conventionerrorviewresolver defaultservlethandlermapping defaultViewResolver Dispatcherservlet dispatcherservletregistration Duplicateserverpropertiesdetector Embeddedservletcontainercustomizerbeanpostprocessor Error Errorattributes Errorpagecustomizer Errorpageregistrarbeanpostprocessor .....

  

When the program starts, Springboot automatically injects 40-50 beans.

Open annotations with @runwith () @SpringBootTest:

@RunWith (Springrunner.class) @SpringBootTest (webenvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public Class Hellocontrollerit {    @LocalServerPort    private int port;    Private URL base;    @Autowired    private testresttemplate template;    @Before public    void SetUp () throws Exception {        this.base = new URL ("http://localhost:" + port + "/");    }    @Test public    void Gethello () throws Exception {        responseentity<string> response = Template.getforentity (Base.tostring (),                string.class);        Assertthat (Response.getbody (), Equalto ("Greetings from Spring boot!");}    }

  

Running it will first open the Sprigboot project, then test, test through

Source Source

Enterprise Distribution Micro Service Cloud Springcloud springboot MyBatis (18) springboot which beans were injected at startup

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.