2.1 默认方法(default method)
- java8引入了一个
default medthod
;
- 用来扩展已有的接口,在对已有接口的使用不产生任何影响的情况下,添加扩展
- 使用
default
关键字
- Spring 4.2支持加载在默认方法里声明的bean
2.2
public class DemoService {
public void doSomething(){
System.out.println("find bean in default method");
}
}
package com.wisely.spring4_2.defaultMethod;
import org.springframework.context.annotation.Bean;
public interface DemoServiceConfig {
@Bean
default DemoService DemoService(){
return new DemoService();
}
}
package com.wisely.spring4_2.defaultMethod;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfig implements DemoServiceConfig{
}
package com.wisely.spring4_2.defaultMethod;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class Main {
public static void main(String[] args) {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext("com.wisely.spring4_2.defaultMethod");
DemoService ds = context.getBean(DemoService.class);
ds.doSomething();
}
}
find bean in default method
分享到:
相关推荐
Spring Security version 3.0.x to 4.2.x Web environment (Spring Security integration cannot work offline) Maven info groupId: org.thymeleaf.extras artifactId: Spring Security 3 integration package: ...
Spring Security-3.0.1 中文官方文档(翻译版) 这次发布的Spring Security-3.0.1 是一个bug fix 版,主要是对3.0 中存在的一些问题进 行修 正。文档中没有添加新功能的介绍,但是将之前拼写错误的一些类名进行...
8. Introducing Spring Boot 9. System Requirements 9.1. Servlet Containers 10. Installing Spring Boot 10.1. Installation Instructions for the Java Developer 10.1.1. Maven Installation 10.1.2. Gradle ...
1)default-init-method ="方法名" 定义在此配置文件中的bean都会执行指定的init方法。 2)default-destroy-method="方法名" 定义在此配置文件中的bean都会在执行指定的destroy方法。 3)default-lazy-init ="false|...
-- 启用spring注解支持 --> <context:annotation-config /> <!-- <bean id="sessionFactory"--> <!-- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">--> <!-- ...
2.3.4. 对OpenID的支持 2.3.4.1. 属性交换 2.3.5. 添加你自己的filter 2.3.5.1. 设置自定义 AuthenticationEntryPoint 2.4. 保护方法 2.4.1. <global-method-security>元素 2.4.1.1. 使用protect-pointcut添加...
2.3.4. 对OpenID的支持 2.3.4.1. 属性交换 2.3.5. 添加你自己的filter 2.3.5.1. 设置自定义 AuthenticationEntryPoint 2.4. 保护方法 2.4.1. <global-method-security> 元素 2.4.1.1. 使用protect-...
实例工厂 <bean bean-factory="" factory-method=""> 管理对象 对象关系DI 构造器注入<construct-arg> set注入 生命周期 scope:prototype/singleton init-method destroy-method API ...
spring+xmemcached aop切面 需要xmemcached-1.2.5+spring-2.5.6 <bean name="factoryMemcachedClient" class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean" destroy-method="shutdown"> $...
3.3. Java 8 (as well as 6 and 7) ............................................................................... 17 3.4. Java EE 6 and 7 ..................................................................
资源释放:<bean destroy-method=""/>仅对单例对象有效 (2)IoC概念 Inversion of Control 控制反转或控制转移 Don't Call Me,We will call you! 控制权:对象的创建和调用关系的控制. (3)DI概念 Dependecy ...
资源释放:<bean destroy-method=""/>仅对单例对象有效 (2)IoC概念 Inversion of Control 控制反转或控制转移 Don't Call Me,We will call you! 控制权:对象的创建和调用关系的控制. (3)DI概念 Dependecy ...
弃用了struts,用spring mvc框架做了几个项目,感觉都不错,而且使用了注解方式,可以省掉一大堆配置文件。本文主要介绍使用注解方式配置的spring mvc,之前写的spring3.0 mvc和rest小例子没有介绍到数据层的内容,...
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; Insert INTO `user` VALUES ('1', 'summer', '100', 'shanghai,pudong'); 到此为止,前期准备工作就完成了。下面开始真正配置mybatis项目了。 1. 在...
Allow java.time types for setting the Last-Modified header [SPR-17571] #22103 StringHttpMessageConverter should assume charset UTF-8 for application/json [SPR-17568] #22100 NettyDataBufferFactory.join...
一、 建立一个新的项目 8 二、 建立spring的配置文件 8 三、 引入spring的jar包 8 四、 测试代码: 8 五、 注意接口的使用: 8 第五课:IOC(DI)配置及应用 9 一、 什么是IOC、DI 9 二、 编辑xml文件时,没有提示 9 ...
在Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: ...
资源释放:<bean destroy-method=""/>仅对单例对象有效 (2)IoC概念 Inversion of Control 控制反转或控制转移 Don't Call Me,We will call you! 控制权:对象的创建和调用关系的控制. (3)DI概念 Dependecy ...
3.3. Java 8 (as well as 6 and 7) ............................................................................... 17 3.4. Java EE 6 and 7 ..................................................................