您的位置:首页 > 其它

SSM 正常启动但不访问404错误

2017-03-31 20:54 85 查看
今天遇到这个问题记住下次可能存在的情况

application.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:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.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-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
<!-- spring 框架配置 -->
<description>Spring Configuration</description>

<!-- 加载配置属性文件 -->
<context:property-placeholder
ignore-unresolvable="true" location="classpath:setting.properties" />

<!-- 使用Annotation自动注册Bean,解决事务失效问题:在主容器中不扫描@Controller注解,在SpringMVC中只扫描@Controller注解。 -->
<context:component-scan base-package="com.sc.tour"><!-- base-package 
如果有多个,用“,”分隔 -->
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 数据源驱动可不写,Druid默认会自动根据URL识别DriverClass -->
<property name="driverClassName" value="${jdbc.driver}" />
<!-- 基本属性url、user、password -->
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<!-- 配置初始化大小、最大值、最小值 -->
<property name="initialSize" value="${jdbc.pool.init}" />
<property name="minIdle" value="${jdbc.pool.minIdle}" />
<property name="maxActive" value="${jdbc.pool.maxActive}" />
<!-- 配置获取链接等待超时的时间 -->
<property name="maxWait" value="60000" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
</bean>
<!-- 配置事务管理器 -->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<!-- 采用@Transactional注解方式使用事务 <tx:annotation-driven /> -->
<!-- 基于AspectJ的xml方式使用事务 -->
<!-- 配置事务的通知 -->
<tx:annotation-driven />
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="do*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<!-- 配置aop切面 -->

<aop:config>
<!-- 配置切入点 -->
<aop:pointcut id="interceptorPointCuts"
expression="execution(* com.sc.tour.*.service.impl.*.*(..))" />
<!-- 配置切面 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" />
</aop:config>
<!-- 对静态资源文件的访问 -->

<!-- sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- <property name="configLocation" value="classpath:mybatis-config.xml" /> -->
<property name="mapperLocations" value="classpath:com/sc/tour/dao/mapper/*.xml" />
</bean>
<!-- 4.配置扫描Dao接口包,动态实现Dao接口,注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<
4000
!-- 给出需要扫描Dao接口包 -->
<property name="basePackage" value="com.sc.tour.dao" />
</bean>

</beans>

spring-mvc.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.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-4.3.xsd">
<mvc:annotation-driven/>

    

    <!-- 加载配置属性文件 -->
<context:property-placeholder ignore-unresolvable="true" location="classpath:setting.properties"/>

<!-- 使用Annotation自动注册Bean,只扫描@Controller -->
<context:component-scan base-package="com.sc.tour.controller" use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

<!-- JSON转换 -->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="ignoreDefaultModelOnRedirect" value="true"/>
<property name="messageConverters">  
<list>  
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>  
</list>  
</property>  
</bean>

<!-- 定义视图文件解析 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="${web.view.prefix}"/>
<property name="suffix" value="${web.view.suffix}"/>
</bean>

<!-- 对静态资源文件的访问, 将无法mapping到Controller的path交给default servlet handler处理 -->
<mvc:default-servlet-handler />

<!-- 静态资源映射 -->

    <mvc:resources mapping="/static/**" location="/static/" cache-period="31536000"/>

<!-- 定义无Controller的path<->view直接映射 -->

<!-- <mvc:view-controller path="/" view-name="redirect:${web.view.index}"/> -->

<!-- 拦截器配置,拦截顺序:先执行后定义的,排在第一位的最后执行。-->
<!-- <mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/user/reserveHostel"/>
<bean class="com.sc.tour.interceptor.LoginInterceptor" />
</mvc:interceptor>
</mvc:interceptors> --> 

<!-- 上传文件拦截,设置最大上传文件大小   10M=10*1024*1024(B)=10485760 bytes   -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
<property name="maxUploadSize" value="${web.maxUploadSize}" />  
</bean>

</beans>

1.可能缺少事务驱动 <tx:annotation-driven />

2.确少mvc驱动   <mvc:annotation-driven/>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: