Java tutorial
/* * Copyright (c) 2013 ITOCHU Techno-Solutions Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.co.ctc_g.rack.api.config; import java.util.concurrent.TimeUnit; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import jp.co.ctc_g.rack.core.config.RackRootContextConfig; import org.glassfish.jersey.servlet.ServletContainer; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.ServletContextInitializer; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; /** * <p> * ????? * </p> * @author ITOCHU Techno-Solutions Corporation. */ @Configuration @Import(RackRootContextConfig.class) public class RackApiContextConfig { @Value("${server.port}") private int port; /** * ?? */ public RackApiContextConfig() { } /** * ??(Tomcat)????? * @return {@link TomcatEmbeddedServletContainerFactory}? */ @Bean public EmbeddedServletContainerFactory tomcat() { TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory(); factory.setPort(port); factory.setSessionTimeout(10, TimeUnit.MINUTES); factory.addInitializers(new ApiWebConfig()); return factory; } /** * <p> * ?????? * </p> * @author ITOCHU Techno-Solutions Corporation. */ public static class ApiWebConfig implements ServletContextInitializer { /** * ?? */ public ApiWebConfig() { } @Override public void onStartup(ServletContext container) throws ServletException { ServletRegistration.Dynamic dispatcher = container.addServlet("jersey", ServletContainer.class); dispatcher.setInitParameter("javax.ws.rs.Application", RackApiApplicationConfig.class.getName()); dispatcher.addMapping("/v1.0/*"); } } }