/** * Invoked when a named value is required, but {@link #resolveName(String, MethodParameter, NativeWebRequest)} * returned {@code null} and there is no default value. Subclasses typically throw an exception in this case. * @param name the name for the value * @param parameter the method parameter * @param request the current request * @since 4.3 */ protected void handleMissingValue(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { handleMissingValue(name, parameter); }
/** * Whether to raise a fatal bind exception on validation errors. * <p>The default implementation delegates to {@link #isBindExceptionRequired(MethodParameter)}. * @param binder the data binder used to perform data binding * @param parameter the method parameter declaration * @return {@code true} if the next method parameter is not of type {@link Errors} * @see #isBindExceptionRequired(MethodParameter) */ protected boolean isBindExceptionRequired(WebDataBinder binder, MethodParameter parameter) { return isBindExceptionRequired(parameter); }
@Test public void straightLineDependency() throws Exception { runTest(new StraightLineDependencyController()); assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4"); assertInvokedBefore("getB1", "getB2", "getC1", "getC2", "getC3", "getC4"); assertInvokedBefore("getB2", "getC1", "getC2", "getC3", "getC4"); assertInvokedBefore("getC1", "getC2", "getC3", "getC4"); assertInvokedBefore("getC2", "getC3", "getC4"); assertInvokedBefore("getC3", "getC4"); }
@Test public void InvertedTreeDependency() throws Exception { runTest(new InvertedTreeDependencyController()); assertInvokedBefore("getC1", "getA", "getB1"); assertInvokedBefore("getC2", "getA", "getB1"); assertInvokedBefore("getC3", "getA", "getB2"); assertInvokedBefore("getC4", "getA", "getB2"); assertInvokedBefore("getB1", "getA"); assertInvokedBefore("getB2", "getA"); }
@Test public void treeDependency() throws Exception { runTest(new TreeDependencyController()); assertInvokedBefore("getA", "getB1", "getB2", "getC1", "getC2", "getC3", "getC4"); assertInvokedBefore("getB1", "getC1", "getC2"); assertInvokedBefore("getB2", "getC3", "getC4"); }
@Test public void unresolvedDependency() throws Exception { runTest(new UnresolvedDependencyController()); assertInvokedBefore("getA", "getC1", "getC2", "getC3", "getC4"); // No other order guarantees for methods with unresolvable dependencies (and methods that depend on them), // Required dependencies will be created via default constructor. }
@ModelAttribute public A getA(Model model) throws IOException { return updateAndReturn(model, "getA", new A()); }
@ModelAttribute public C1 getC1(Model model) throws IOException { return updateAndReturn(model, "getC1", new C1()); }
@ModelAttribute public C3 getC3(Model model) throws IOException { return updateAndReturn(model, "getC3", new C3()); }
@ModelAttribute public C4 getC4(@ModelAttribute C3 c3, Model model) throws IOException { return updateAndReturn(model, "getC4", new C4()); } }
@ModelAttribute public C4 getC4(@ModelAttribute B2 b2, Model model) throws IOException { return updateAndReturn(model, "getC4", new C4()); } }
@ModelAttribute public C4 getC4(@ModelAttribute B2 b2, Model model) throws IOException { return updateAndReturn(model, "getC4", new C4()); } }
@ModelAttribute public C1 getC1(@ModelAttribute B2 b2, Model model) throws IOException { return updateAndReturn(model, "getC1", new C1()); }
@ModelAttribute public C1 getC1(@ModelAttribute B1 b1, Model model) throws IOException { return updateAndReturn(model, "getC1", new C1()); }
@ModelAttribute public C3 getC3(@ModelAttribute B2 b2, Model model) throws IOException { return updateAndReturn(model, "getC3", new C3()); }
@ModelAttribute public B1 getB1(@ModelAttribute A a, Model model) throws IOException { return updateAndReturn(model, "getB1", new B1()); }
@ModelAttribute public C2 getC2(@ModelAttribute B1 b1, Model model) throws IOException { return updateAndReturn(model, "getC2", new C2()); }
@ModelAttribute public C2 getC2(@ModelAttribute B1 b1, Model model) throws IOException { return updateAndReturn(model, "getC2", new C2()); }
@ModelAttribute public B1 getB1(@ModelAttribute C1 c1, @ModelAttribute C2 c2, Model model) throws IOException { return updateAndReturn(model, "getB1", new B1()); }
@ModelAttribute public A getA(@ModelAttribute B1 b1, @ModelAttribute B2 b2, Model model) throws IOException { return updateAndReturn(model, "getA", new A()); }