三.Bean定义 1.开启bean定义注解支持 开启注解支持须添加以下配置项: <context:component-scan base-package="cn.matt"/> 2.支持bean定义的注解 Spring自带@Component注解及扩展@Repository.@Service.@Controller,用于定义bean,如图所示 上述注解默认的bean名字是以小写开头的类名(不包含包名),bean的名字也可由注解的value属性明确指定 @Service pu…
一.概述 所谓零配置,并不是说一点配置都没有了,而是配置很少而已.通过约定来减少需要配置的数量,提高开发效率. 零配置实现主要有以下两种方式: 惯例优先原则:也称为约定大于配置(convention over configuration),即通过约定代码结构或命名规范来减少配置数量,但不会减少配置文件. 基于注解的规约配置:通过在指定类上指定注解,约定其含义来减少配置数量,从而提高开发效率:如事务注解@Transaction是基于注解的规约,在指定的类或方法上使用该注解就表示其需要事务. Spr…
XML配置的优缺点: 优点有:1. XML配置方式进一步降低了耦合,使得应用更加容易扩展,即使对配置文件进一步修改也不需要工程进行修改和重新编译.2. 在处理大的业务量的时候,用XML配置应该更加好一些.因为XML更加清晰的表明了各个对象之间的关系,各个业务类之间的调用.同时spring的相关配置也能一目了然.当然,有人会说,用XML配置,在大的业务量时候会使得XML文件过大,不容易查看.这一点我们完全可以利用业务分解书写多个XML配置文件就可以了. 3.xml,在乎:整体业务关系:维护性. 缺…
随着越来越多地使用Springboot敏捷开发,更多地使用注解配置Spring,而不是Spring的applicationContext.xml文件. Configuration注解: Spring解析为配置类,相当于spring配置文件 Bean注解:容器注册Bean组件,默认id为方法名 @Configuration public class AppConfig { @Bean public MyService myService() { return new MyServiceImpl()…
@Resourse(name="  xxx") 意味从上下文找xxx名字一样的然后引入 @Repository("personDao") 意味生成一个 bean 以便于让其他高业务层的去找这个 的bean spring.xml新加入 xmlns:context="http://www.springframework.org/schema/context" http://www.springframework.org/schema/context…
AOP 即 Aspect Oriental Program 面向切面编程 先来一个栗子: <aop:config> <aop:pointcut id="loggerCutpoint" expression= "execution(* com.how2java.service.ProductService.*(..)) "/> <aop:aspect id="logAspect" ref="loggerAsp…
转载网址:http://blog.sina.com.cn/s/blog_4c6e822d0102dv63.html <!-- Struts2 need begin-->  <filter>   <filter-name>struts2</filter-name>   <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  </fil…
注解方式 applicationContext.xml 加入下面配置 <!--Spring Aop 启用自动代理注解 --> <aop:aspectj-autoproxy proxy-target-class="true"/> LoggingAspect,java package com.lingdong.spring.aop; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotati…
servlet3.0+规范后,允许servlet,filter,listener不必声明在web.xml中,而是以硬编码的方式存在,实现容器的零配置. ServletContainerInitializer:启动容器时负责加载相关配置 package javax.servlet; import java.util.Set; public interface ServletContainerInitializer { public void onStartup(Set<Class<?>&g…
与SpringSecurity的配置类似,spring同样为我们提供了一个实现类WebMvcConfigurationSupport和一个注解@EnableWebMvc以帮助我们减少bean的声明. applicationContext-MvcConfig.xml <!-- 启用注解,并定义组件查找规则 ,mvc层只负责扫描@Controller --> <context:component-scan base-package="web.function" use-d…