Step 1. Download the latest JDK version.
Check the current version of Java.
Now we are going to update the version of Java.
Now, as we know, copy the bin folder root path and set the environment variable.
Check the current version of Java; it's an updated version.
Step 2. Install Maven.
Now, as we know, copy the bin folder root path and set the environment variable.
Step 3. Create a Spring Boot.

Step 3. Use Maven clean press Ctrl.
Step 3. Use Maven clean press Ctrl.
Step 3. Normal way to get the output from the constructor.
a:- Constructor Call normal way
b:- Constructor Call Spring Boot.
:- If you get the error shown in the screenshot below.
// WRONG (Tomcat internal class - does not have getBean)
import org.apache.catalina.core.ApplicationContext;
// CORRECT (Spring Framework class)
import org.springframework.context.ApplicationContext;
b:- Constructor and method call Spring Boot.
When we add the component, they create the bean for that.
c:- Constructor and method call Spring Boot.

When integrating with a third-party system and the availability of specific methods is uncertain, we define a bean to manage the communication and processing.
src\main\java\com\bitsnbytes\product\ProductApplication.java
package com.bitsnbytes.product;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class ProductApplication {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(ProductApplication.class, args);
MyApp myApp= context.getBean(MyApp.class);
myApp.run();
}
}
src\main\java\com\bitsnbytes\product\MyApp.java
package com.bitsnbytes.product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class MyApp {
private final MyComponent myComponent;
@Autowired
public MyApp(MyComponent myComponent) {
this.myComponent = myComponent;
}
public void run() {
myComponent.getMessage();
}
}src\main\java\com\bitsnbytes\product\MyComponent.javapackage com.bitsnbytes.product;
import org.springframework.stereotype.Component;
public class MyComponent {
public MyComponent(){
System.out.println("Result From Component");
}
public void getMessage(){
System.out.println("Result From Get Message");
}
}src\main\java\com\bitsnbytes\product\MyAppConfig.javapackage com.bitsnbytes.product;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MyAppConfig {
@Bean
public MyComponent myComponent(){
return new MyComponent();
}
}









No comments:
Post a Comment
If you have any problem please let me know.