|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2014 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import java.util.List;
|
22 | 22 | import java.util.Map;
|
23 | 23 |
|
| 24 | +import org.hamcrest.Matchers; |
24 | 25 | import org.junit.Before;
|
25 | 26 | import org.junit.Test;
|
26 | 27 |
|
| 28 | +import org.springframework.context.annotation.Bean; |
| 29 | +import org.springframework.context.annotation.Configuration; |
27 | 30 | import org.springframework.core.io.ClassPathResource;
|
28 | 31 | import org.springframework.core.io.Resource;
|
| 32 | +import org.springframework.mock.web.test.MockServletContext; |
| 33 | +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; |
| 34 | +import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; |
29 | 35 |
|
30 | 36 | import static org.junit.Assert.*;
|
31 | 37 |
|
@@ -88,4 +94,34 @@ private void initTranslator() {
|
88 | 94 | this.translator.setHandlerMap(this.handlerMap);
|
89 | 95 | }
|
90 | 96 |
|
| 97 | + // SPR-12592 |
| 98 | + @Test |
| 99 | + public void initializeOnce() throws Exception { |
| 100 | + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); |
| 101 | + context.setServletContext(new MockServletContext()); |
| 102 | + context.register(HandlerMappingConfiguration.class); |
| 103 | + context.refresh(); |
| 104 | + ResourceUrlProvider translator = context.getBean(ResourceUrlProvider.class); |
| 105 | + assertThat(translator.getHandlerMap(), Matchers.hasKey("/resources/**")); |
| 106 | + assertFalse(translator.isAutodetect()); |
| 107 | + } |
| 108 | + |
| 109 | + @Configuration |
| 110 | + public static class HandlerMappingConfiguration { |
| 111 | + @Bean |
| 112 | + public SimpleUrlHandlerMapping simpleUrlHandlerMapping() { |
| 113 | + ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler(); |
| 114 | + HashMap<String, ResourceHttpRequestHandler> handlerMap = new HashMap<String, ResourceHttpRequestHandler>(); |
| 115 | + handlerMap.put("/resources/**", handler); |
| 116 | + SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping(); |
| 117 | + hm.setUrlMap(handlerMap); |
| 118 | + return hm; |
| 119 | + } |
| 120 | + |
| 121 | + @Bean |
| 122 | + public ResourceUrlProvider resourceUrlProvider() { |
| 123 | + return new ResourceUrlProvider(); |
| 124 | + } |
| 125 | + } |
| 126 | + |
91 | 127 | }
|
0 commit comments