2424import org .junit .jupiter .api .Test ;
2525import org .springframework .aop .framework .ProxyFactory ;
2626import org .springframework .aop .support .AopUtils ;
27+ import org .springframework .context .support .StaticApplicationContext ;
2728import org .springframework .data .rest .core .config .RepositoryRestConfiguration ;
2829import org .springframework .stereotype .Controller ;
2930import org .springframework .util .ReflectionUtils ;
@@ -45,7 +46,7 @@ void setUp() {
4546
4647 doReturn (URI .create ("" )).when (configuration ).getBasePath ();
4748
48- mapping = new HandlerMappingStub (configuration );
49+ mapping = getHandlerMappingStub (configuration );
4950 }
5051
5152 @ Test // DATAREST-1132
@@ -85,7 +86,7 @@ void doesNotRejectAtRequestMappingOnStandardMvcController() {
8586 void combinesBasePathAndControllerPrefixesCorrectly () throws Exception {
8687
8788 doReturn (URI .create ("/base" )).when (configuration ).getBasePath ();
88- mapping = new HandlerMappingStub (configuration );
89+ mapping = getHandlerMappingStub (configuration );
8990
9091 var method = ReflectionUtils .findMethod (PrefixedController .class , "someMethod" );
9192 var info = mapping .getMappingForMethod (method , PrefixedController .class );
@@ -105,6 +106,15 @@ private static Class<?> createProxy(Object source) {
105106 return proxy .getClass ();
106107 }
107108
109+ private static HandlerMappingStub getHandlerMappingStub (RepositoryRestConfiguration configuration ) {
110+
111+ HandlerMappingStub mapping = new HandlerMappingStub (configuration );
112+ mapping .setApplicationContext (new StaticApplicationContext ());
113+ mapping .afterPropertiesSet ();
114+
115+ return mapping ;
116+ }
117+
108118 @ BasePathAwareController
109119 static class SomeController {}
110120
0 commit comments