Jersey支持spring3配置

1. web.xml配置


	
		contextConfigLocation
		classpath*:spring-*.xml
	
	
		org.springframework.web.context.ContextLoaderListener
		
	

	
	
		Jersey Web Application
		org.glassfish.jersey.servlet.ServletContainer
		
		
			jersey.config.server.provider.packages
			com.lianlian.box.web.resource
		
		1
	
	
		Jersey Web Application
		/webapi/*
	

2.spring的配置就不详说了


3. jersey的Resource,这里的@Component注解是spring的

@Component
@Path("/tp/ad")
public class TpAdRequestResource {
	
	@Resource
	private AdService adService;

	@Path("/apply")
	@Produces(MediaType.APPLICATION_JSON)
	public AdApplyRespParam adApply(@BeanParam AdApplyReqParam param) {
		adService.sendAdApplyRequest(param);
		return null;
	}
	
}

4. 只加注解还不够,一定要引入jersey-spring3的Jar包。百度了好长时间,都没get到重点,google第一篇就找到了,原文地址:https://jersey.java.net/documentation/latest/spring.html

		
			org.glassfish.jersey.ext
			jersey-spring3
			2.23
		


你可能感兴趣的:(工作中的那些坑)