Я застрял! Если я пропущу тесты и развернусь для автоматической проводки tomcat, файл свойств конфигурации будет работать. В моем тесте это терпит неудачу! Я не уверен, что мне не хватает.Свойства конфигурации впрыска не работают в моем тесте
Вот мои настройки:
Spring Загрузочный v 1.2.5.RELEASE Application.yml
git:
localRepo: './powershell-status-scripts/'
remoteRepo: 'https://github.com/...'
RepositoryProperties этот класс имеет методы получения и установки для свойств
@Configuration
@ConfigurationProperties(locations = "classpath:application.yml", prefix = "git", ignoreUnknownFields = false)
public class RepositoryProperties {
private String localRepo;
private String remoteRepo;
public RepositoryProperties() {
}
public String getLocalRepo() {
return localRepo;
}
public void setLocalRepo(String localRepo) {
this.localRepo = localRepo;
}
public String getRemoteRepo() {
return remoteRepo;
}
public void setRemoteRepo(String remoteRepo) {
this.remoteRepo = remoteRepo;
}
}
Применение .java
@EnableAutoConfiguration
@EnableConfigurationProperties
@ComponentScan(basePackages = "com.sendash.admin")
@EnableJpaRepositories("com.sendash.admin.dao.jpa")
@EnableSwagger
public class Application extends SpringBootServletInitializer {
private static final Class<Application> applicationClass = Application.class;
private static final Logger log = LoggerFactory.getLogger(applicationClass);
public static void main(String[] args) {
SpringApplication.run(applicationClass, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(applicationClass);
}
}
GitService - Autowiring свойства работает на tomcat!
@Service
@EnableConfigurationProperties
public class GitService {
@Autowired
private RepositoryProperties repositoryProperties;
public void updateLocalRepository() {
...
}
GitServiceTest этот класс терпит неудачу при инициализации из-за NPE. Свойства - null.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Application.class)
@Profile("test")
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
public class GitServiceTest {
@Autowired
private static GitService manager;
@Autowired
private static RepositoryProperties properties;
private static final String localRepoLocation = properties.getLocalRepo();
Я понимаю, после того, как наклеивать это, что @EnableConfigurationProperties на обоих Application.java и класса GitService.java. Остановка дублирования не устраняет проблему.