그래서 Maven이있는 Felix에 기반한 OSGi 번들 내에 원격 Rest (JSON) 서비스를 만들려고합니다.Felix OSGi 컨테이너에서 Spring Rest Json Service
내 기본 서비스 인터페이스 :
public class RestFileServiceImpl implements RestFileService{
public String getFile(Long id) {
return "test service";
}
}
은 일반적으로 난 내 web.xml을
<servlet>
<servlet-name>spring-mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc-dispatcher</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
이를 추가 그리고이 잘 작동 할 인터페이스의
@Controller
@RequestMapping("/s/fileService")
public interface RestFileService {
@RequestMapping(value = "/file", method = RequestMethod.POST)
@ResponseBody
public String getFile(Long id);
}
내 구현 정상적인 웹 애플리케이션 내부. 하지만 지금은 이것을 OSGi 번들 안에 넣고 싶습니다. 나는 펠릭스 알고
public class Activator implements BundleActivator {
private static Log sLog = LogFactory.getLog(Activator.class);
public void start(BundleContext context) throws Exception {
/*
* Exposing the Servlet
*/
Dictionary properties = new Hashtable();
context.registerService(RestFileService.class.getName(), new RestFileServiceImpl(), properties);
sLog.info("Registered Remote Rest Service");
}
public void stop(BundleContext context) throws Exception {
sLog.info("Unregistered Remote Rest Service");
}
}
:
서블릿 3.0 그래서 난이 내 OSGi 프레임 활성화하는 RestServlet
@WebServlet(value="/rest", name="rest-servlet")
public class RestServlet implements ServletContextListener {
private static Log sLog = LogFactory.getLog(RestServlet.class);
public void contextInitialized(ServletContextEvent arg0) {
sLog.info("initializing the Rest Servlet");
}
public void contextDestroyed(ServletContextEvent arg0) {
sLog.info("un-initializing the Rest Servlet");
}
}
을 만들어 은 web.xml없이 서블릿을 선언 @WebServlet을 사용할 수 있습니다 JAX로 자체 http 구현을하지만, 스프링 애노테이션과 XML을 가능한 한 작게하려고 시도하고있다. 주석 구동 3.0 서블릿을 강제로 등록 할 수 있습니까?
내가 뭘 잘못하고 있니? 이게 가능한가?