yaml file

 server:

  port: 8080

ms:
applicationName: MS9
version: 1.0
package az.ingress.ms9;

import az.ingress.ms9.singleton.Flyable;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Ms9Application implements CommandLineRunner {

@Autowired
private Flyable flyable;

@Autowired
@Qualifier("animal")
private Flyable flyable2;

@Value("${ms.applicationName}")
private String applicationName;

// public Ms9Application(@Qualifier("bird") Flyable flyable, @Qualifier("animal") Flyable flyable2) {
// this.flyable = flyable;
// this.flyable2 = flyable2;
// }

public static void main(String[] args) {
SpringApplication.run(Ms9Application.class, args);
}

@Override
public void run(String... args) throws Exception {
System.out.println(applicationName);
}
}
package az.ingress.ms9.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

@ConfigurationProperties("ms")
@Data
@Component
public class ApplicationProperties {

List<String> developers;
}
package az.ingress.ms9;

import az.ingress.ms9.config.ApplicationProperties;
import az.ingress.ms9.singleton.Flyable;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;

import java.util.List;

@SpringBootApplication
@EnableConfigurationProperties
@RequiredArgsConstructor
public class Ms9Application implements CommandLineRunner {

private final Flyable flyable;
private final Flyable flyable2;
private final ApplicationProperties properties;

@Value("${ms.applicationName}")
private String applicationName;

@Value("${ms.developers")
private List<String> developers;

public static void main(String[] args) {
SpringApplication.run(Ms9Application.class, args);
}

@Override
public void run(String... args) throws Exception {
System.out.println(properties.getDevelopers());
}
}

Комментарии

Популярные сообщения из этого блога

Lesson1: JDK, JVM, JRE

SE_21_Lesson_11: Inheritance, Polymorphism

SE_21_Lesson_9: Initialization Blocks, Wrapper types, String class