package zx.soft.sample.jetty.beans;

import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.stereotype.Component;

@Component
public class CustomizationEmbeddedServletContainer implements EmbeddedServletContainerCustomizer {

	@Value("${server.port}")
	private String port;

	@Value("${server.address}")
	private String address;

	@Value("${server.sessionTimeout}")
	private String sessionTimeout;

	//方式一:编程方式的自定义
	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		container.setPort(Integer.parseInt(port));
		container.setAddress(InetAddress )
		container.setSessionTimeout(Integer.parseInt(sessionTimeout));
	}

	//方式二:直接定义ConfigurableEmbeddedServletContainer
	@Bean
	public EmbeddedServletContainerFactory servletContainer() {
		JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory();
		factory.setPort(Integer.parseInt(port));
		factory.setSessionTimeout(Integer.parseInt(sessionTimeout), TimeUnit.MINUTES);
		return factory;
	}

	@Bean
	public Jackson2ObjectMapperBuilder objectMapperBuilder() {
		Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
		builder.dateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH));
		return builder;
	}

}

@@ -30,16 +30,45 @@
 beans;%0A%0A
+import java.net.InetAddress;%0A
 import j
@@ -853,16 +853,71 @@
 izer %7B%0A%0A
+%09private static final InetAddress InetAddress = null;%0A%0A
 %09@Value(
@@ -1230,45 +1230,8 @@
 ));%0A
-%09%09container.setAddress(InetAddress )%0A
 %09%09co

修改sample-jetty中嵌入式设置InetAddress