小编use*_*569的帖子

加载构造函数时值为null

Properties我没有在构造函数内部使用,而是看到@Value注解可以解决问题。

它可以在我拥有的另一个实现中工作,但在这里没有

控制器:

@Autowired
private Customer customer;
Run Code Online (Sandbox Code Playgroud)

我的课

@Service
public class Customer {

    /** The soap GW endpoint. */
    @Value("${soapGWEndpoint}")
    private String soapGWEndpoint;

    /** The soap GW app name. */
    @Value("${soapGWApplName}")
    private String soapGWAppName;

    /** The soap GW user. */
    @Value("${generic.user}")
    private String soapGWUser;

    /** The soap GW password. */
    @Value("${generic.user.password}")
    private String soapGWPassword;

    public Customer () {
        // All parameters are null:
        login(soapGWEndpoint, soapGWAppName, soapGWUser, soapGWPassword);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是它们位于application.properties文件中。

为什么在这种情况下我不能使用@Value?

java spring

3
推荐指数
2
解决办法
484
查看次数

标签 统计

java ×1

spring ×1