有办法使用您问题中提到的相同版本来解决此问题,
如果需要不提第二种方法,第一种方法是通过 web.xml 加载 sring,如下所示,作为正常的 spring 配置:
<servlet>
<servlet-name>project-spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:project-spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>project-spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
现在通过应用程序加载你的球衣资源,如下所示:
@ApplicationPath("/rest")
public class ResourceLoader extends Application
{
/* (non-Javadoc)
* @see javax.ws.rs.core.Application#getClasses()
*/
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> classes = new HashSet<Class<?>>();
loadResourceClasses(classes);
return classes;
}
private void loadResourceClasses(Set<Class<?>> classes)
{
classes.add(StudentResource.class);
}
}
然后在您的资源中:
@Path("student")
class StudentResource
{
private StudentService studentService;
StudentResource(@Context ServletContext servletContext)
{
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
this.transactionService = applicationContext.getBean(StudentService .class);
}
}
你去 Spring 已经配置了所有的依赖注入和 Jersey !!!