REST服务没有在Apache中注册使用Spring和Maven

时间:2014-02-13 14:34:40

标签: java spring maven apache-wink apache-wink-spring

我有一个Maven项目,其中包含下面列出的依赖项:

enter image description here

wink.version = 1.1.3-incubating and spring.version = 3.0.5.RELEASE

Spring中的应用程序上下文包括:

    <bean class="org.apache.wink.spring.Registrar">
    <property name="classes">
        <set value-type="java.lang.Class">
        </set>
    </property>
    <property name="instances">
        <set>
            <ref local="restexample" />
        </set>
    </property>
    </bean>
    <bean id="restexample" class="com.example.rest.ExampleRest"></bean>

web.xml包括:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:META-INF/wink/wink-core-context.xml
        classpath:applicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>restServlet</servlet-name>
    <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>restServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

Rest Java Class包括:

@Path("/ex")
public class ExampleRest {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public String example() throws IOException {
        return "{ 'id':'test' }";
    }
}

查看日志我没有看到任何例外或问题,&#39; restexample&#39;正在创建bean,但是当我尝试调用REST服务时,我得到了 404

我认为Apache Wink没有注册 ExampleRest

有什么想法吗?

更新02/14 : 在日志中,我注意到Apache Wink没有注册ExampleRest。也许,问题出在bean声明中,或者可能是我使用的依赖项。 我还设置了另一个没有弹簧的项目,它在那里工作。我真的需要Spring将他的IoD用于daos和服务。

1 个答案:

答案 0 :(得分:2)

在您的web.xml中,您指向一个名为 wink-core-context.xml 的文件。这个文件的路径似乎是错误的。它应该是:

  

META-INF /服务器/眨眼芯context.xml中

See source

不确定为什么你在这里看不到FileNotFoundException。