Question: I have set the variable "spring.profiles.active" in my environment to "test" and I have below file in my src/main/resources.

**application-test.properties**

It has one property "machine"

```
machineName=mumbai

```

I want to access this property in one of my Java based class.

```
package com.test.service;

@Component
@RequiredArgsConstructor
public class TestMachine {

    @Value("${machineName}")
    private String machineName;

    @Override
    public void checkMachine() {
        System.out.println(machineName);
    }
}

```

**PropertiesConfig class:**

```
@Configuration
public class PropertiesUtils {

    public static void initProperties() {
        String activeProfile = System.getProperty("spring.profiles.active");
        if (activeProfile == null) {
            activeProfile = "test";
        }
        PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
        Resource[] resources = new ClassPathResource[] {new ClassPathResource("application.properties"),
                        new ClassPathResource("application-" + activeProfile + ".properties")};
        propertySourcesPlaceholderConfigurer.setLocations(resources);
    }
}

```

But while running this as a Spring boot application in Eclipse. I am getting below error:

```
Error creating bean with name 'TestMachine': Injection of autowired dependencies failed;

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'machineName' in value "${machineName}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180) ~[spring-core-5.3.9.jar:5.3.9]

```

What am I missing? I found this way only in most of the websites.

Answer: 
What matters is the same interface:

```golang
package main

import (
    "fmt"
)

type Item interface{
    fmt.Stringer
}

type ItemA struct {
}

func (a ItemA) String() string {
    return "item A"
}

type ItemB struct {
}

func (a ItemB) String() string {
    return "item B"
}

func main() {
    items := make([]Item, 0)
    items = append(items, ItemA{}, ItemB{})
    fmt.Printf("Items: %v", items)
}

```
What you seem to be expecting is `subtype polymorphism`. Go does not support dynamic binding for non-interface types. Therefore you you could either use interfaces

```
package main

func main(){
    var bar Bar
    var foo Foo
    foo.Symbols = append(foo.Symbols, bar)
}

type Symbol interface {
    Symbol()
}

type Base struct {
    a int32
}

func (b Base)Symbol(){}

type Foo struct {
    Base
    b int32
    Symbols []Symbol
}

type Bar struct {
    Base
    c int32
}

```

or if you dislike using interfaces, you can use a trick like below with reflect.

```
package main

import "fmt"

func main(){
    var bar Bar
    var foo Foo
    err := foo.AddSymbol(bar)
    if err != nil{
        fmt.Println(err)
    }
}

type Base struct {
    a int32
}

func (b Base)Symbol(){}

type Foo struct {
    Base
    b int32
    symbol []interface{} // field made private
}

// AddSymbol : helper to append values
func (f *Foo)AddSymbol(in interface{})(err error){
    if f.symbol == nil{
        f.symbol = make([]interface{},0)
    }

    switch typ := in.(type) {
    case Base,Bar,Foo:
        f.symbol = append(f.symbol,in)
    default:
        return fmt.Errorf("provided type: %s is not supported",typ)
    }

    return nil
}

type Bar struct {
    Base
    c int32
}

```