前两天 项目 快要结尾的时候,我们需要 程序 需要 完善一个log 日志记录 。 日志记录 由拦截器 每次触发,log 每次 记录到 数据库中, 接下来是 注解代码的实现 和配置文件。。
首先 配置 数据库连接 文件。 persistence.xml
"
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="sxm_cpbh" transaction-type="RESOURCE_LOCAL">// 数据持久化的 名称 数据持久化的类型
<provider>org.hibernate.ejb.HibernatePersistence</provider> //hibernate持久化
<properties>
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.driver.OracleDriver"/> //数据库驱动名称
<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@192.168.96.251:1521:~~~~"/>//数据库 名称 url
<property name="hibernate.connection.username" value="~~~~"/>
<property name="hibernate.connection.password" value="~~~~"/>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/> // 方言
<property name="hibernate.show_sql" value="true"/> //执行 时显示 sql语句
</persistence-unit>
</persistence>
"
接下来是 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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- 自动扫描包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.cmcc.*"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
//当配为<aop:aspectj-autoproxy
poxy-target-class="true"/>时,表示使用CGLib动态代理技术织入增强。不过即使proxy-target-class设置为false,如果目标类没有声明接口,则spring将自动使用CGLib动态代理。
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>
text/html;charset=UTF-8
</value>
</list>
</property>
</bean>
<!-- Validator -->
<mvc:annotation-driven validator="validator"/> // Spring 的 控制器 (应该是 IOC)
<bean id="validator"
class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
<property name="validationMessageSource" ref="messageSource"/>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
<property name="fileEncodings" value="utf-8"/>
<property name="cacheSeconds" value="120"/>
</bean>
-------------------------------------------------------------------------------------------------------------------
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding">
<value>
UTF-8
</value>
</property>
<property name="maxUploadSize">
<value>
32505856
</value>
<!-- 上传文件大小限制为31M,31*1024*1024 -->
</property>
<property name="maxInMemorySize">
<value>
4096
</value>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--<property name="dataSource" ref="dataSource"/>-->
<property name="persistenceUnitName" value="sxm_cpbh"/>
<property name="persistenceXmlLocation" value="classpath:META-INF/ct_persistence.xml"/>
</bean>
//实体工厂 bean
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
</beans>
"
"<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:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd"
default-autowire="byName"
>
<!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties" />
<context:annotation-config />
<!-- 自动扫描(自动注入) -->
<context:component-scan base-package="com.cmcc.soc" />
<aop:aspectj-autoproxy proxy-target-class="true"/>
</beans>"
" 注解 方法 的 接口
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public @interface WSCLogging {
}
"
待续。。。
相关推荐
Spring Mvc AOP通过注解方式拦截controller等实现日志管理
Spring MVC 拦截器Spring MVC 拦截器
Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于注解实例Spring MVC 基于...
Spring Boot mvc web拦截器实现权限访问控制等功能(csdn)————程序
网上很多人想使用注解拦截spring mvc action中的一个方法,实现方法很多,一般是通过在拦截器中分析url路径来实现, 使用自定义注解的方式来标注要拦截的 action 中的某个方法, 没有很好的解决方法, 如果通过借助spring...
Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块。Spring MVC4是当前zuixin的版本,在众多特性上有了进一步的提升。, 在精通Spring MVC4中,我们将会从头开始构建一个有用的Web应用。本书共计10章,分别介绍了...
用STS(Spring Tool Suite)开发的,spring mvc + spring security 实现的最简单的登录系统,无数据库。
spring mvc 拦截器获取请求数据信息 解压之后放到项目中 直接运行就可以了 (将流多次运用)
spring mvc拦截器,过滤json数据中的null值,将null变成空字符串,内含截图,及jar包
spring mvc 注解 拦截器 对一个数据库表进行了增删改查操作 ,初学spring mvc框架的 可以参考 代码下载直接可以运行!~~
IT学习者Spring MVC注解实例.pdf
spring mvc 注解 拦截器 对一个数据库表进行了增删改查操作 ,初学spring mvc框架的 可以参考 代码下载直接可以运行!~~ 包含jar和数据库sql语句
使用 Spring MVC + JDBC Template 实现筛选、检索功能(maven),图文教程地址:https://blog.csdn.net/qq_40147863/article/details/86187642
spring mvc 过滤器,实现url过滤,权限模块经常用到的,很不错
基于spring+spring mvc+mybatis框架整合实现超市货物管理系统(实现登入功能、mysql数据库的增删改查及分页显示)
maven、spring、spring mvc、mybatis 整合实现ssm通用增删改查基础开发框架.maven、spring、spring mvc、mybatis 整合实现ssm通用增删改查基础开发框架.maven、spring、spring mvc、mybatis 整合实现ssm通用增删改查...
主要介绍了详解Spring MVC拦截器实现session控制,使用session监听,重复登录后,强制之前登录的session过期。有兴趣的可以了解一下。
主要介绍Spring MVC 的使用注解来配置的使用实例