BAEL-3835 (#8901)
* BAEL-3835: Inject a value to a static field * BAEL-3835: integration of code into the src directory Co-authored-by: Georgios Charitakis <georgios.charitakis@prodyna.com>
This commit is contained in:
parent
4131d1ebbd
commit
8c56c4ef43
@ -0,0 +1,16 @@
|
||||
package com.baeldung.staticvalue.injection;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication
|
||||
@PropertySource("/application.properties")
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.baeldung.staticvalue.injection;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class PropertyController {
|
||||
|
||||
@Value("${name}")
|
||||
private String name;
|
||||
|
||||
@Value("${name}")
|
||||
private static String NAME_NULL;
|
||||
|
||||
private static String NAME_STATIC;
|
||||
|
||||
@Value("${name}")
|
||||
public void setNameStatic(String name){
|
||||
PropertyController.NAME_STATIC = name;
|
||||
}
|
||||
|
||||
@GetMapping("/properties")
|
||||
public List<String> getProperties(){
|
||||
return Arrays.asList(this.name, NAME_STATIC, NAME_NULL) ;
|
||||
}
|
||||
}
|
1
spring-core-3/src/main/resources/application.properties
Normal file
1
spring-core-3/src/main/resources/application.properties
Normal file
@ -0,0 +1 @@
|
||||
name = Inject a value to a static field
|
Loading…
x
Reference in New Issue
Block a user