pring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
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"> <!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="yzyq.controller" /> <!-- 避免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> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
</list>
</property>
</bean> <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/" p:suffix=".jsp" /> <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> </beans>

spring-mybatis.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: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/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.0.xsd
"> <!-- JNDI方式配置数据源 -->
<!-- <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="${jndiName}"></property> </bean> --> <!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="url" value="${jdbc_url}" />
<property name="username" value="${jdbc_username}" />
<property name="password" value="${jdbc_password}" /> <!-- 初始化连接大小 -->
<property name="initialSize" value="0" />
<!-- 连接池最大使用连接数量 -->
<property name="maxActive" value="20" />
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="20" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="0" />
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="60000" /> <!-- <property name="poolPreparedStatements" value="true" /> <property name="maxPoolPreparedStatementPerConnectionSize" value="33" /> --> <property name="validationQuery" value="${validationQuery}" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<property name="testWhileIdle" value="true" /> <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="25200000" /> <!-- 打开removeAbandoned功能 -->
<property name="removeAbandoned" value="true" />
<!-- 1800秒,也就是30分钟 -->
<property name="removeAbandonedTimeout" value="1800" />
<!-- 关闭abanded连接时输出错误日志 -->
<property name="logAbandoned" value="true" /> <!-- 监控数据库 -->
<!-- <property name="filters" value="stat" /> -->
<property name="filters" value="mergeStat" />
<!-- 连接属性 -->
<propertyname="connectionProperties">
<value>clientEncoding=UTF-8</value>
</property>
</bean> <!-- myBatis文件 -->
<beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean">
<propertyname="dataSource"ref="dataSource" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<propertyname="mapperLocations"value="classpath:yzyq/mapping/*.xml" />
</bean> <beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer">
<propertyname="basePackage"value="yzyq.mapper" />
<propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory" />
</bean> <!-- 配置事务管理器 -->
<beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<propertyname="dataSource"ref="dataSource" />
</bean> <!-- 注解方式配置事物 -->
<!-- <tx:annotation-driven transaction-manager="transactionManager" /> --> <!-- 拦截器方式配置事物 -->
<tx:adviceid="transactionAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="add*"propagation="REQUIRED" />
<tx:methodname="append*"propagation="REQUIRED" />
<tx:methodname="insert*"propagation="REQUIRED" />
<tx:methodname="save*"propagation="REQUIRED" />
<tx:methodname="update*"propagation="REQUIRED" />
<tx:methodname="modify*"propagation="REQUIRED" />
<tx:methodname="edit*"propagation="REQUIRED" />
<tx:methodname="delete*"propagation="REQUIRED" />
<tx:methodname="remove*"propagation="REQUIRED" />
<tx:methodname="repair"propagation="REQUIRED" />
<tx:methodname="delAndRepair"propagation="REQUIRED" /> <tx:methodname="get*"propagation="SUPPORTS" />
<tx:methodname="find*"propagation="SUPPORTS" />
<tx:methodname="load*"propagation="SUPPORTS" />
<tx:methodname="search*"propagation="SUPPORTS" />
<tx:methodname="datagrid*"propagation="SUPPORTS" /> <tx:methodname="*"propagation="SUPPORTS" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcutid="transactionPointcut"expression="execution(* yzyq.service..*Impl.*(..))" />
<aop:advisorpointcut-ref="transactionPointcut"advice-ref="transactionAdvice" />
</aop:config> <!-- 配置druid监控spring jdbc -->
<beanid="druid-stat-interceptor"class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor">
</bean>
<beanid="druid-stat-pointcut"class="org.springframework.aop.support.JdkRegexpMethodPointcut"scope="prototype">
<propertyname="patterns">
<list>
<value>yzyq.service.*</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisoradvice-ref="druid-stat-interceptor"pointcut-ref="druid-stat-pointcut" />
</aop:config> </beans>

spring.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" 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
"> <!-- 引入属性文件 -->
<context:property-placeholder location="classpath:config.properties" /> <!-- 自动扫描(自动注入) -->
<context:component-scan base-package="yzyq.service" /> </beans>

Spring注解问题,[action中注入service失败的更多相关文章

  1. Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程

    最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...

  2. Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法

    Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...

  3. 如何在Java的Filter中注入Service???

    今天在做用户使用cookie自动登录的时候,发现在LoginFilter中读取到cookie以后要进行查询数据库然后进行用户名和密码的比对,查询数据库肯定要用到Service和Dao,一开始我以为在s ...

  4. 如何在Java Filter 中注入 Service

    在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...

  5. 关于如何在Listener中注入service和ServletContextListener源码分析

      今天在做项目时突然发现我该如何向listener中注入service对象,因为监听器无法使用注解注入. 此时有人会想用以下代码通过xml的方式注入: ApplicationContext cont ...

  6. SpringBoot注入Service失败

    Description: The bean 'userService' could not be injected as a 'com.phy.hemanresoruce.service.UserSe ...

  7. spring boot测试类自动注入service或dao

    使用Spring Boot进行单元测试时,发现使用@Autowired注解的类无法自动注入,当使用这个类的实例的时候,报出NullPointerException,即空指针异常. Spring Boo ...

  8. 如何将service绑入到spring 并且在action中使用

    第一步:定制 service接口,为什么用接口我也不清楚 package com.inspur.services; import com.hsp.domain.User; public interfa ...

  9. Spring注解@Component、@Repository、@Service、@Controller区别 .

    Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...

随机推荐

  1. Hadoop-2.x启动HDFS和YARN的方式

    逐一启动(实际生产环境中的启动方式) * sbin/hadoop-daemon.sh start|stop namenode|datanode|journalnode * sbin/yarn-daem ...

  2. ubuntu linux 下 mysql 学习笔记

    '#' 后为注释 以下为在shell中的操作: 打开终端(terminal)1.登录MySQL mysql-u root -p 输入密码:******2.几个简单的命令 (1)show databas ...

  3. 常用js类型相互转换

    数字转换为字符串 var a=200.21;document.write(a.toString(10));  结果为:200.21以十进制转换 document.write(a.toFixed(3)) ...

  4. LinQ 创建连接、简单增删改查

    LINQ--语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展.它允许编写C#或者Visual Basic代码以查询数据库相同的方式操 ...

  5. 融云发送手机短信验证短信(.net版本)

    首先本次需求是在MVC5中进行的,通过收费的融云服务来验证手机号码,而且本次的项目也是前后台分离,所以添加了WEBAPI2,那么先添加WEBAPI的接口 using System; using Sys ...

  6. Jenkins的安装与系统配置

    Jenkins的安装 Jenkins的安装需要一个安装包:http://pan.baidu.com/s/1hqQBruc,也可以去Jenkins官网上下载,Jenkins的官网地址 http://Je ...

  7. UltraEdit的配置

    这两天看同学门写的博客,很多人都是些的配置文件如何配置,看完以后感觉获益很大啊,从dos中不在需要输入javac.exe文件的地址就可以访问到javac的文件,为我们的java的编译提供了很大的帮助. ...

  8. C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 39 章 Windows 服务(上)),不对的地方欢迎指出与交流. 章节出自<Professional C ...

  9. 微信小程序开发之http到https的转化

    小程序从公布到现在已经过去好几个月了,本来从小程序发布出来就准备抱着微信的大腿进行一波小程序开发的,但是由于公司项目小程序暂时不支持,也就只能一直搁浅.过年过来偶然和朋友谈起小程序,觉的工作再忙也得找 ...

  10. C++ 中的 delete[] 机制剖析

    本文简单总结了delete[]放在析构函数中VS放在主函数中的区别(针对自己定义类). delete原理简单剖析(摘至https://zhidao.baidu.com/question/1540902 ...