私のコントローラからJSON/XMLデータを返す必要があります。私が見つけたものから、@ResponseBody
が私のメソッドに必要で、そのためには<mvc:annotation-driven>
が有効です。私はあらゆる種類のRnDを試しましたが、まだまだ立ち往生しています! :(要素 'mvc:annotation-driven'の宣言が見つかりません
どうやら私の問題は私のservlet.xmlファイル(スキーマイマイチが有効になっ!) にあり、私は春の3.1.1 &を使用していますが、明示的に私のクラスパスに春-MVC-3.1.1.jarに入れています。
ここに私のサーブレット・コンテキストファイルのサンプル-servlet.xmlです:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc-3.1 http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.sample.controller"/>
<mvc:annotation-driven/>
<!--Use JAXB OXM marshaller to marshall/unmarshall following class-->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="xmlViewer"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
<value>com.sample.model.SampleClass</value>
</list>
</property>
</bean>
</constructor-arg>
</bean>
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>
私のコントローラクラスは、次のようになります。
@Controller
public class XmlController {
@RequestMapping(value="/getXml",method = RequestMethod.POST)
public @ResponseBody AssociateDetail getXml(){
System.out.println("inside xml controller.....");
AssociateDetail assoBean=null;
try{
AssociateService add=new AssociateService();
assoBean=add.selectAssociateBean();
}catch(Exception e){
e.printStackTrace();
}
return assoBean;
}
}
今の問題は<mvc:annotation-driven />
あるエラーを与える:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
そして、私はすべての回避策は、このサイト上とを超えて提案しようとしています。 Spring 3.1.1と@ResponseBody
を使用して、スキーマの名前空間を更新しました。
をはい!それは私が推測していたようでした..正しいXSDのためにありがとう:) また、このxsdはURL経由で検証されます。そこからxsd&validateのローカルコピーを保持する方法はありますか? – user2164016
これは実際に働いたインターネット全体の唯一の答えでした。インターネットは非常に大きな場所です。 –
ありがとうございました。 –