@Restcontroller无效, 依然去解析视图

mclubing 2016-05-09 05:32:56
controller:

@RestController
public class CommodityController {

@RequestMapping("test.htm")
public String test() {
return "test";
}
}


spring版本:

<org.springframework.version>4.2.0.RELEASE</org.springframework.version>

但是依然解析视图:
...全文
1312 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mclubing 2016-05-09
  • 打赏
  • 举报
回复
引用 1 楼 u010425898 的回复:
配置文件贴出来
已经好了,我加了个 <mvc:annotation-driven/>就行了
mclubing 2016-05-09
  • 打赏
  • 举报
回复
引用 1 楼 u010425898 的回复:
配置文件贴出来
这是配置文件, applicationContext.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:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.2.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <bean id="placeholderConfig"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:dataSource.properties">
        </property>
    </bean>

    <!-- c3p0连接池配置 -->
    <bean id="merchantDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="maxPoolSize" value="20"/>
        <property name="minPoolSize" value="2"/>
        <property name="initialPoolSize" value="2"/>
        <property name="maxIdleTime" value="60"/>
        <property name="checkoutTimeout" value="3000"/>
        <property name="acquireIncrement" value="2"/>
        <property name="acquireRetryAttempts" value="0"/>
        <property name="acquireRetryDelay" value="1000"/>
        <property name="autoCommitOnClose" value="false"/>
        <property name="automaticTestTable" value="Test"/>
        <property name="breakAfterAcquireFailure" value="false"/>
        <property name="idleConnectionTestPeriod" value="60"/>
        <property name="maxStatements" value="100"/>
        <property name="maxStatementsPerConnection" value="5"/>
    </bean>

    <bean id="merchantSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="merchantDataSource"/>
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <property name="mapperLocations">
            <list>
                <value>classpath:com/allo2o/common/mapper/*.xml
                </value>
            </list>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/pages/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.allo2o.common.mapper"/>
        <property name="sqlSessionFactoryBeanName" value="merchantSqlSessionFactory"/>
    </bean>

    <!-- 事务管理器 -->
    <bean id="txManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="merchantDataSource"/>
    </bean>

    <!-- dispatch-servlet.xml中配置
        @Transactional注解只能添加再带@service的注解的类或者方法上!!!!!!!!!!!!!!!!! -->
    <tx:annotation-driven transaction-manager="txManager"/>

    <context:component-scan base-package="com.allo2o.common.*"/>

    <context:component-scan base-package="com.merchant"/>

    <bean id="sequenceRangeGenerator"
          class="com.allo2o.common.biz.sequence.mybatis.MybatisSequenceRangeGenerator">
    </bean>
    <bean id="auditSequence"
          class="com.allo2o.common.biz.sequence.longimpl.LongSequence">
        <property name="name" value="AUDIT"/>
        <property name="sequenceRangeGenerator" ref="sequenceRangeGenerator"/>
    </bean>
    <bean id="accountSequence"
          class="com.allo2o.common.biz.sequence.longimpl.LongSequence">
        <property name="name" value="AccountDO"/>
        <property name="sequenceRangeGenerator" ref="sequenceRangeGenerator"/>
    </bean>

    <bean id="contentManager"
          class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <property name="favorPathExtension" value="true"/>
        <property name="ignoreAcceptHeader" value="true"/>
        <property name="defaultContentType" value="text/html"/>
        <property name="useJaf" value="false"/>
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json"/>
                <entry key="html" value="text/html"/>
                <entry key="xml" value="application/xml"/>
            </map>
        </property>
    </bean>

    <bean id="messageSource"
          class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="useCodeAsDefaultMessage" value="true"/>
        <property name="basenames">
            <list>
                <value>conf/common/uri</value>
            </list>
        </property>
    </bean>

</beans>
dispatch-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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.2.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
 http://www.springframework.org/schema/util
 http://www.springframework.org/schema/util/spring-util-4.2.xsd">


    <context:component-scan base-package="com.merchant.*">
        <!-- @Transactional注解只能添加再带@service的注解的类或者方法上!!!!!!!!!!!!!!!!! -->
        <context:exclude-filter type="annotation"  expression="org.springframework.stereotype.Service" />
    </context:component-scan>

    <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
        <property name="maxUploadSize" value="200000"/>
    </bean>

    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
            </props>
        </property>
    </bean>

    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>application/json;charset=utf-8</value>
            </list>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <util:list id="beanList">
                <ref bean="mappingJacksonHttpMessageConverter"/>
            </util:list>
        </property>
    </bean>

    <!-- <mvc:default-servlet-handler /> -->
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>all.o2o.merchant</param-value>
	</context-param>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:log4j.properties</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>

	<filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
 	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping> 
</web-app>
  • 打赏
  • 举报
回复
配置文件贴出来

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧