0

i have service like :

public class ServiceImpl implements Service {
...
private Integer days;

//constructor
public UserServiceImpl(@Value("${test.days}") Integer days,
                              .....)
}

I pass varable from applicatin.yml and when i run my project it works fine. But when i run my tests i get exception :

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ServiceImpl#0': Unsatisfied dependency expressed through constructor parameter 11; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "${test.days}"

seems like it cant see my value from application.yml and trying to wrap string "${test.days}" to Integer...how to avoid this ?

2 Answers2

0

above of private Integer days; you can put @Value and the name of the property in application.properties and in your methods of your class use days property directly

mamJavad
  • 49
  • 8
0

Looks lile its impossible for me, so i made Configuration class and mock it in test. https://stackoverflow.com/a/62871732/10358410 I want to emphasize that when you run the application, everything works fine, the problem is only in the tests.