我在连接环境到我的Spring项目时遇到了问题。 在这个类中
@Configuration
@ComponentScan(basePackages = "my.pack.offer.*")
@PropertySource("classpath:OfferService.properties")
public class PropertiesUtil {
@Autowired
private Environment environment;
@Bean
public String load(String propertyName)
{
return environment.getRequiredProperty(propertyName);
}
}
环境变量始终为空。
@Resource
而不是@Autowired
。看看是否有帮助。 - Paulius MatulionisPropertiesUtil
中唯一的代码吗?您是否有一个类似于PropertySourcesPlaceholderConfigurer
的东西? - Marc-AndrePropertyUtil
的呢? - M. Deinum