Posted In: Pattern, Spring

Use of strategy pattern in Spring – ContentNegotiationStrategy

Strategy pattern

The strategy pattern

  • defines a family of algorithms,
  • encapsulates each algorithm, and
  • makes the algorithms interchangeable within that family.

Spring defines following strategy classes which implements ContentNegotiationStrategy

FixedContentNegotiationStrategy

ParameterContentNegotiationStrategy

PathExtensionContentNegotiationStrategy

ServletPathExtensionContentNegotiationStrategy

Then uses org.springframework.web.accept.ContentNegotiationManager to apply strategy.

public ContentNegotiationManager(ContentNegotiationStrategy... strategies) {
	this(Arrays.asList(strategies));
}

Tags:

by , on July 25th, 2017

  • Categories