0% found this document useful (0 votes)
2 views4 pages

ComponentScan Annotation

The document consists of Java code for a Spring Boot application, including the main application class, configuration class, and service classes. It initializes the application context, retrieves beans for MyService and OutServ, and executes their respective methods. The application is structured with proper annotations for configuration and component scanning.

Uploaded by

Gauri Hallale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

ComponentScan Annotation

The document consists of Java code for a Spring Boot application, including the main application class, configuration class, and service classes. It initializes the application context, retrieves beans for MyService and OutServ, and executes their respective methods. The application is structured with proper annotations for configuration and component scanning.

Uploaded by

Gauri Hallale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1)

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
{

public static void main(String[] args)


{
ConfigurableApplicationContext

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;

public class MyService {

public void doWork()


{
System.out.println("I AM Done ");
}
}
4)

package outjspm;

public class OutServ {

public void show()


{
System.out.println("show");
}
}

You might also like