尝试通过外部属性文件读取SpringBoot应用程序中的属性。
@SpringBootApplication
@Configuration
@PropertySource({"file:${DOCUMENT_CONVERTER_PROPERTIES}"})
public class ConverterApplication {
public static void main(String[] args) {
SpringApplication.run(ConverterApplication.class, args);
}
}
此处,DOCUMENT_CONVERTER_PROPERTIES是环境变量中添加的文件F:\PROPPERTIES\converter\documentConverter. properties的保持器。
ConverterService.java
@Service
public class ConverterService {
@Autowired
private Environment environment;
String tempPDFPath = environment.getProperty(Constants.TEMP_PDF_PATH);
String tempDocxPath = environment.getProperty(Constants.TEMP_DOCX_PATH);
ConverterServiceTest.java
@SpringBootTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ExtendWith(SpringExtension.class)
//@TestPropertySource("classpath:/")
public class ConverterServiceTest {
@Autowired
private ConverterService service;
private byte[] bytes = null;
@Test
void testConvertDocxToPDF(){
createFile("<path>/myFile.docx"); //put this file at given location
service.convertDocxToPDF(bytes);
}
这里缺少什么,任何帮助都是感激的提前感谢!!
1条答案
按热度按时间wlzqhblo1#
在Windows中生成URI时出现问题。您的PropertySource导致
file:F:\PROPPERTIES\converter\documentConverter.properties
.我认为正确的格式是
file:///F:/PROPPERTIES/converter/documentConverter.properties
路径中的反斜杠可能有效,但开头的斜杠(
file:///
)是强制性的...