ComponentScan Annotation
ComponentScan Annotation
package com.jspm;
import
org.springframework.boot.SpringApplicatio
n;
import
org.springframework.boot.autoconfigure.Sp
ringBootApplication;
import
org.springframework.context.ConfigurableA
pplicationContext;
import com.jspm.service.MyService;
import outjspm.OutServ;
@SpringBootApplication
public class McaFirstSbProjectApplication
{
container=SpringApplication.run(McaFirstS
bProjectApplication.class, args);
System.out.println("Welcome to
SpringBoot");
MyService
m=container.getBean(MyService.class);
m.doWork();
OutServ
o=container.getBean(OutServ.class);
o.show();
}
//ConfigurableApplicationContext
2)
package com.jspm.config;
import
org.springframework.context.annotation.Be
an;
import
org.springframework.context.annotation.Co
mponentScan;
import
org.springframework.context.annotation.Co
nfiguration;
import com.jspm.service.MyService;
import outjspm.OutServ;
@Configuration
@ComponentScan("outjspm")
public class MyConfig {
@Bean
public MyService myserv()
{
return new MyService();
}
@Bean
public OutServ serving()
{
return new OutServ();
}
}
3)
package com.jspm.service;
package outjspm;