spring-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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <mvc:annotation-driven></mvc:annotation-driven>
<!--<mvc:annotation-driven conversion-service="formattingConversionService"></mvc:annotation-driven>-->
<mvc:resources mapping="/static/**" location="/statics/"></mvc:resources>
<mvc:resources mapping="/resources/**" location="/resources/"></mvc:resources>
<context:component-scan base-package="com.lingdong.controller"></context:component-scan>
<context:component-scan base-package="com.lingdong.thymeleaf"></context:component-scan>
<!-- 配置视图解析器 -->
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/resources/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>-->
<!--spring thymeleaf视图解析器-->
<bean id="springResourceTemplateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="/resources/views/"/>
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="true" />
<property name="characterEncoding" value="UTF-8"/> </bean>
<!--<bean id="formattingConversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="formatters">
<set>
<bean class="com.lingdong.thymeleaf.DateFormatter"/>
</set>
</property>
</bean>-->
<bean id="springTemplateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="springResourceTemplateResolver"/>
<property name="enableSpringELCompiler" value="true"/> </bean>
<!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/resources/jsps/"/>
<property name="suffix" value=".jsp"/>
<property name="order" value="2"/>
<property name="viewNames" value="*jsp"/>
</bean>-->
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="springTemplateEngine"/>
<property name="characterEncoding" value="UTF-8"/> </bean> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="exception"/>
<property name="exceptionAttribute" value="ex"/>
<property name="exceptionMappings">
<props>
<prop key="NumberFormatException">numberException</prop>
<prop key="NullPointerException">runtimeException</prop>
<prop key="RuntimeException">runtimeException</prop>
<prop key="ClassCastException">runtimeException</prop>
</props>
</property>
</bean>
<!-- 从请求和响应 读取/编写字符串 -->
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</beans>

spring-security.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"> <security:http pattern="/statics/**" security="none"/>
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/login.do" access="isAnonymous()"/>
<security:intercept-url pattern="/register.do" access="isAnonymous()"/>
<security:intercept-url pattern="/registerusers.do" access="isAnonymous()"/>
<security:intercept-url pattern="/useradd.do" access="isAnonymous()"/>
<security:intercept-url pattern="/admins/**" access="hasRole('ROLE_ADMIN')"/>
<security:intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
<security:csrf disabled="false" token-repository-ref="cookieCsrfTokenRepository" />
<security:form-login login-page="/login.do" login-processing-url="/login" username-parameter="username" password-parameter="password" authentication-failure-url="/login.do?error=true" />
<security:logout invalidate-session="true" logout-url="/logout" logout-success-url="/login.do"/>
<security:http-basic />
<security:remember-me data-source-ref="dataSource" key="youkey" remember-me-parameter="remember-me"/>
<security:session-management>
<security:concurrency-control />
</security:session-management>
</security:http>
<security:authentication-manager>
<!--静态添加的用户登录信息-->
<!--<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="admin123" authorities="ROLE_USER,ROLE_ADMIN"/>
<security:user name="user" password="user123" authorities="ROLE_USER"/>
</security:user-service>
</security:authentication-provider>-->
<security:authentication-provider>
<security:password-encoder ref="bCryptPasswordEncoder"/>
<security:jdbc-user-service id="userDetailsService" data-source-ref="dataSource"
users-by-username-query="SELECT username,password,enabled FROM users WHERE username=?"
authorities-by-username-query="SELECT u.username as username,r.rolename as authority FROM users u join userrole ur on u.userid=ur.userid join roles r on r.roleid=ur.roleid WHERE u.username=?"
/>
</security:authentication-provider>
</security:authentication-manager> <bean id="bCryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/>
<bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="hideUserNotFoundExceptions" value="false"/>
<property name="userDetailsService" ref="userDetailsService"/>
<property name="passwordEncoder" ref="bCryptPasswordEncoder"/> </bean>
<bean id="cookieCsrfTokenRepository" class="org.springframework.security.web.csrf.CookieCsrfTokenRepository">
<property name="cookieHttpOnly" value="false"/>
</bean> </beans>

spring mvc 和spring security配置 spring-servlet.xml和spring-security.xml设置的更多相关文章

  1. Spring MVC 使用tomcat中配置的数据源

    Spring MVC 使用tomcat中配置的数据源 配置tomcat数据源 打开tomcat目录下的conf目录,编辑sever.xml目录.在<GlobalNamingResources&g ...

  2. Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务

    Spring Boot 是 Spring 的一套快速配置脚手架,可以基于Spring Boot 快速开发单个微服务,Spring Cloud是一个基于Spring Boot实现的云应用开发工具:Spr ...

  3. Spring MVC 学习总结(八)——Spring MVC概要与环境配置(IDEA+Maven+Tomcat7+JDK8、示例与视频)

    一.MVC概要 MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范,用一种将业务逻辑.数据.显示分离的方法组织代码,MVC主要作用是降低了视图与业务 ...

  4. Spring MVC + Velocity实现国际化配置

    国际化介绍 web开发中,国际化是需要考虑的一个问题,而且这个问题一般是越早敲定越好(不然等到系统大了,翻译是个问题).下面是结合实际项目(Spring MVC+Velocity)对实现国际化的一些总 ...

  5. spring mvc:练习:javaConfig配置和注解

    Spring4 MVC HelloWorld 注释/JavaConfig为示例,一步一步以简单的方式学习Spring4 MVC 的注解,项目设置,代码,部署和运行. 我们已经使用XML配置开发了一个H ...

  6. spring, spring mvc, mybatis整合文件配置详解

    转自:http://www.cnblogs.com/wxisme/p/4924561.html 使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用 ...

  7. Spring MVC环境搭建和配置

    1. 创建Dynamic web project 2. 修改WEB-INF/web.xml,内容如下: <?xml version="1.0" encoding=" ...

  8. spring mvc 500错误Allocate exception for servlet AppService javax.naming.NamingException: Cannot create resource instance 竟是@Resource的原因

    头几天已经测试的完毕了,换了个目录出现这个问题 严重: Allocate exception for servlet AppService javax.naming.NamingException: ...

  9. spring MVC项目中,欢迎页首页根路径到底是怎么设置的

    0. 问题: 如何改mvc中项目的欢迎页,或者叫做根路径 一个东西快弄完了,就剩下一个问题,应该是个小问题.就是mvc项目的欢迎页,怎么给改下呢. 这个项目是通过mvn建立的,整个项目的原型就是spr ...

  10. Spring MVC第一课:用IDEA构建一个基于Spring MVC, Hibernate, My SQL的Maven项目

    作为一个Spring MVC新手最基本的功夫就是学会如何使用开发工具创建一个完整的Spring MVC项目,本文站在一个新手的角度讲述如何一步一步创建一个基于Spring MVC, Hibernate ...

随机推荐

  1. Velocity初探小结--velocity使用语法详解

    做java开发的朋友一般对JSP是比较熟悉的,大部分人第一次学习开发View层都是使用JSP来进行页面渲染的,我们都知道JSP是可以嵌入java代码的,在远古时代,java程序员甚至在一个jsp页面上 ...

  2. 转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38

    转:ORA-15186: ASMLIB error function = [asm_open], error = [1], 2009-05-24 13:57:38http://space.itpub. ...

  3. Linux LVM逻辑卷配置过程详解

    许多Linux使用者安装操作系统时都会遇到这样的困境:如何精确评估和分配各个硬盘分区的容量,如果当初评估不准确,一旦系统分区不够用时可能不得不备份.删除相关数据,甚至被迫重新规划分区并重装操作系统,以 ...

  4. Linux设备管理(四)_从sysfs回到ktype

    sysfs是一个基于ramfs的文件系统,在2.6内核开始引入,用来导出内核对象(kernel object)的数据.属性到用户空间.与同样用于查看内核数据的proc不同,sysfs只关心具有层次结构 ...

  5. js分页页码算法

    function get_hs_page(cur_page, total_page) { var result = ""; ; i <= total_page; i++) { ...

  6. js月份,日期加一天

    js没有直接可以用的函数,所以只能自己写,其中需要涉及到每个月天数的判断,如果是2月份的话,还要涉及到闰年的判断 var addDate = { //日期,在原有日期基础上,增加days天数,默认增加 ...

  7. 拥抱.NET Core,如何开发一个跨平台类库 (1)

    在此前的文章中详细介绍了使用.NET Core的基本知识,如果还没有看,可以先去了解“拥抱.NET Core,学习.NET Core的基础知识补遗”,以便接下来的阅读. 在本文将介绍如何配置类库项目支 ...

  8. Nodejs之MEAN栈开发(八)---- 用户认证与会话管理详解

    用户认证与会话管理基本上是每个网站必备的一个功能.在Asp.net下做的比较多,大体的思路都是先根据用户提供的用户名和密码到数据库找到用户信息,然后校验,校验成功之后记住用户的姓名和相关信息,这个信息 ...

  9. Egret 集成第三方库 记录

    引入第三方库pureMVC 这次我们要使用到一个mvc开发框架-pureMVC,熟悉as3的朋友一定也对这个框架不陌生吧.不熟悉的也没关系,这个框架不是这次的主角.我们从 这里 下载pureMVC的T ...

  10. Win下最爱效率利器:AutoHotKey

    AutoHotkey是一个windows下的开源.免费.自动化软件工具.它由最初旨在提供键盘快捷键的脚本语言驱动(称为:热键),随着时间的推移演变成一个完整的脚本语言.但你不需要把它想得太深,你只需要 ...