и посмотреть медиа
Java | Interview questions
и посмотреть медиа
Questions and answers for Java developer interviews.
Questions and answers for Java developer interviews.
AI bot for text-to-speech and voice cloning in Telegram. Create audio using neural network quickly and easily.
Selection of typical questions in Java interviews: from JVM basics to Spring and Hibernate. Each question with detailed explanation, code examples, and tips. Suitable for all levels.
🤔 Чем отличается компонент от бина? В Spring оба термина – Bean и Component – связаны с управляемыми объектами, но у них разное предназначение. 🚩Что такое `@Component`? @Component делает класс Spring-бином автоматически. Spring сам создаст и зарегистрирует объект в контейнере. import org.springframework.stereotype.Component; @Component public class Car { public void drive() { System.out.println("Машина едет..."); } } Как получить объект? import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); Car car = context.getBean(Car.class); car.drive(); } } 🚩Что такое `@Bean`? @Bean создаёт Bean вручную в @Configuration-классе. Можно использовать, если нужно передать параметры или создать Bean из библиотеки. import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class AppConfig { @Bean public Car car() { return new Car(); // Создаём объект вручную } } Как получить Bean? ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); Car car = context.getBean(Car.class); Ставь 👍 и забирай 📚 Базу знаний
Открыть канал и посмотреть медиаOnly registered users can share their opinion.
Be the first to share your impression of this resource!