我有一个简单的应用程序,我使用几个属性文件来获取其他用户编辑的内容(链接到网站等).
我加载属性的类看起来像这样:
@Configuration
@PropertySource("classpath:salestipsWhitelist.properties")
public class SalestipsWhitelist {
@Autowired
Environment env;
public Environment getEnv() {
return env;
}
public void setEnv(Environment env) {
this.env = env;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
}
Run Code Online (Sandbox Code Playgroud)
一些属性文件:
UPS_MPP_M_L=True
UPS_MPP_M_M=True
UPS_MPP_M_MP=True
UPS_MPP_M_S=True
Run Code Online (Sandbox Code Playgroud)
这工作正常,但如果我对属性文件进行更改,我必须重新加载应用程序以可视化所做的任何更改.
如果我将位置移动到磁盘而不是类路径,是否有可能定期或手动重新加载?我不希望在更改时自动完成此操作,因为我想控制何时完成/更新.
我正在尝试编写测试以确保我的控制器加载我的视图.
这样做时,我得到一个"圆形视图路径异常".这是由于百里叶视图解析器没有出现.
一个简单的控制器方法如下所示:
@Cacheable("Customers")
@RequestMapping(value="/customer", method = RequestMethod.GET)
public String customer(Model model) {
model.addAttribute("customer", "customer");
return "customer";
}
Run Code Online (Sandbox Code Playgroud)
我的视图位于src/main/resources/templates(通过spring-boot进行autoconfig),在这个exapmle中,视图被命名customer.html.如果我将视图名称更改为与@requestMapping的值不同,那么我将避免错误ofc.
我如何提供Spring-boot-autoconfig为我的测试创建的ThymeleafViewResolver?
这个问题表明我必须这样做,但没有说明如何......:如何避免Spring MVC测试中的"循环视图路径"异常
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class CustomerControllerTest {
@Autowired
CustomerController customerController;
private MockMvc mockMvc;
@Before
public void setup(){
// Process mock annotations
MockitoAnnotations.initMocks(this);
// Setup Spring test in stand-alone mode
this.mockMvc = MockMvcBuilders.standaloneSetup(customerController).build();
}
@Test
public void testLoadCustomerPage() throws Exception{
this.mockMvc.perform(get("/customer")).andExpect(status().isOk());
}
}
Run Code Online (Sandbox Code Playgroud)
javax.servlet.ServletException: Circular view path [customer]: would dispatch …Run Code Online (Sandbox Code Playgroud)