Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.demo;
- import org.springframework.beans.factory.annotation.Required;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.annotation.*;
- import org.springframework.stereotype.Component;
- class Address {
- private String street;
- private int number;
- public Address(String street, int number) {
- this.street = street;
- this.number = number;
- }
- public void setNumber(int number) {
- this.number = number;
- }
- public int getNumber() {
- return number;
- }
- public String getStreet() {
- return street;
- }
- public void setStreet(String street) {
- this.street = street;
- }
- }
- @Component
- class Company {
- private Address address;
- public Company(Address address) {
- this.address = address;
- }
- public void setAddress(Address address) {
- this.address = address;
- }
- public Address getAddress() {
- return address;
- }
- }
- @ComponentScan(basePackageClasses = Company.class, excludeFilters = {
- @ComponentScan.Filter(type = FilterType.ANNOTATION, value = Configuration.class)
- })
- class Config {
- @Bean(name = "address")
- public Address getAddress() {
- return new Address("High Street", 1000);
- }
- }
- @SpringBootApplication
- public class DemoApplication {
- public static void main(String[] args) {
- //SpringApplication.run(DemoApplication.class, args);
- ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
- Company asd = context.getBean("company", Company.class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement