转载地址:http://blog.csdn.net/cr135810/article/details/52302387
最近搭建了一个框架,开始用的spring3.1.1 后来升级到spring4.2.0,把遇到的问题记录一下当做备份了
1、Java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget(Ljava/lang/String;)Z
这个问题是因为,我的项目里有两个aop的jar包一个是之前的3.1.1一个是4.2.0,把3.1.1的删除掉就好了
2、org.springframework.web.servlet.view.ContentNegotiatingViewResolver的配置
invalid property ‘mediatypes’ of bean [org.springframework.web.servlet.view.ContentNegotiatingViewResolver] 遇到一个这个错误
spring3 是这样的
- <bean
- class=”<span style=”color:#ff0000;”>org.springframework.web.servlet.view.ContentNegotiatingViewResolver</span>”>
- <property name=“order” value=“1”></property>
- <property name=“mediaTypes”>
- <map>
- <!– 告诉视图解析器,返回的类型为json格式 –>
- <entry key=“json” value=“application/json” />
- <entry key=“xml” value=“application/xml” />
- <entry key=“htm” value=“text/htm” />
- </map>
- </property>
- <property name=“defaultViews”>
- <list>
- <!– ModelAndView里的数据变成JSON –>
- <bean
- class=“org.springframework.web.servlet.view.json.MappingJacksonJsonView” />
- </list>
- </property>
- <property name=“ignoreAcceptHeader” value=“true”></property>
- </bean>
<bean
class="<span style="color:#ff0000;">org.springframework.web.servlet.view.ContentNegotiatingViewResolver</span>">
<property name="order" value="1"></property>
<property name="mediaTypes">
<map>
<!-- 告诉视图解析器,返回的类型为json格式 -->
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="htm" value="text/htm" />
</map>
</property>
<property name="defaultViews">
<list>
<!-- ModelAndView里的数据变成JSON -->
<bean
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
</list>
</property>
<property name="ignoreAcceptHeader" value="true"></property>
</bean>
spring4 就得改为下面这个样子,问题就解决了
- <bean
- class=”<span style=”color:#ff0000;”>org.springframework.web.accept.ContentNegotiationManagerFactoryBean</span>”>
- <property name=“favorPathExtension” value=“true” />
- <property name=“favorParameter” value=“true” />
- <property name=“ignoreAcceptHeader” value=“true”></property>
- <property name=“defaultContentType” value=“text/html” />
- <property name=“mediaTypes”>
- <map>
- <!– 告诉视图解析器,返回的类型为json格式 –>
- <entry key=“json” value=“application/json” />
- <entry key=“xml” value=“application/xml” />
- <entry key=“htm” value=“text/htm” />
- <entry key=“file” value=“application/octet-stream” />
- <entry key=“image” value=“image/*” />
- </map>
- </property>
- </bean>
<bean
class="<span style="color:#ff0000;">org.springframework.web.accept.ContentNegotiationManagerFactoryBean</span>">
<property name="favorPathExtension" value="true" />
<property name="favorParameter" value="true" />
<property name="ignoreAcceptHeader" value="true"></property>
<property name="defaultContentType" value="text/html" />
<property name="mediaTypes">
<map>
<!-- 告诉视图解析器,返回的类型为json格式 -->
<entry key="json" value="application/json" />
<entry key="xml" value="application/xml" />
<entry key="htm" value="text/htm" />
<entry key="file" value="application/octet-stream" />
<entry key="image" value="image/*" />
</map>
</property>
</bean>
3、问题找不到了,直接说一下修改的地方吧就是jackson的问题
spring3的配置如下
- <!–避免IE执行AJAX时,返回JSON出现下载文件 –>
- <bean id=“mappingJacksonHttpMessageConverter”
- class=”org.springframework.http.converter.json.<span style=”color:#ff0000;”>MappingJacksonHttpMessageConverter</span>”>
- <property name=“supportedMediaTypes”>
- <list>
- <value>text/html;charset=UTF-8</value>
- </list>
- </property>
- </bean>
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.<span style="color:#ff0000;">MappingJacksonHttpMessageConverter</span>">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
spring4的配置如下
- <!–避免IE执行AJAX时,返回JSON出现下载文件 –>
- <bean id=“mappingJacksonHttpMessageConverter”
- class=”org.springframework.http.converter.json.<span style=”color:#ff0000;”>MappingJackson2HttpMessageConverter</span>”>
- <property name=“supportedMediaTypes”>
- <list>
- <value>text/html;charset=UTF-8</value>
- </list>
- </property>
- </bean>
<!--避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.<span style="color:#ff0000;">MappingJackson2HttpMessageConverter</span>">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
两个的区别就是 文件名字变了,已做标红处理
4、有个asm的jar包在spring4已经不需要单独加载这个jar包了,删掉即可