ViewScope implements Scope { @Override public Object get(String name, ObjectFactory objectFactory) { Map<String, Object> viewMap = getViewRoot().getViewMap(); Object bean = viewMap.get(name); if (bean == null) { bean = objectFactory.getObject(); viewMap.put(name, bean); } return bean; }  @Override Object get(String name, ObjectFactory objectFactory); @Override @Nullable Object remove(String name); @Override @Nullable String getConversationId(); @Override void registerDestructionCallback(String name, Runnable callback); @Override @Nullable Object resolveContextualObject(String key); static final String SCOPE_VIEW; static final String DESTRUCTION_CALLBACK_NAME_PREFIX; }
@Test public void testGet() { AtomicInteger count = new AtomicInteger(0); ObjectFactory<?> objectFactory = (ObjectFactory<Object>) () -> { count.incrementAndGet(); return new Object(); }; Object bean = this.viewScope.get(KEY, objectFactory); assertThat(count).hasValue(1); bean = this.viewScope.get(KEY, objectFactory); assertThat(count).hasValue(1); assertThat(this.viewScope.remove(KEY)).isEqualTo(bean); }