Spring boot application properties are all read as null

Viewed 21

In my application class I have

@SpringBootApplication(scanBasePackages = {"com.binance.bot.timeandsales", <some other packages>})

@Configuration @EnableScheduling public class BinanceTimeAndSalesApplication implements CommandLineRunner {

@Autowired
AggTradeEventSubscriptionListener aggTradeEventSubscriptionListener;

And in the bean class which is a non-public class in the same file I have

@Component
class AggTradeEventSubscriptionListener implements SubscriptionListener<AggregateTradeEvent> {  
    @Value("${binance.api}")
    private String apiUrl;

which is coming as null.

In my application.properties I have

  binance.api=https://fapi.binance.com

The application.properties in src/main/resources directory which is also appearing as the resources directory in the Intellij module configuration. In my pom.xml I have

<properties>
  <start-class>com.binance.bot.timeandsales.BinanceTimeAndSalesApplication</start-class>
</properties>

What am I doing wrong that the application properties are read as null? Another weirdity is that in some other class in a different package, the properties are getting read. But not in the newer classes that I'm writing in the com.binance.bot.timeandsales package, which is specified as one of the packages to scan in the Configuration.

1 Answers

Try adding @Configuration to AggTradeEventSubscriptionListener.

Related