首页 技术 正文
技术 2022年11月17日
0 收藏 429 点赞 2,818 浏览 1549 个字
package ch2.annotation;//target/elementType用来设定注解的使用范围
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;//表明这个注解documented会被javac工具记录
import java.lang.annotation.Documented;//retention/retentionPolicy(保留)注解,在编译的时候会被保留在某个(那个)特定的编译阶段
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;//target/elementType用来设定注解的使用范围:type用于类或接口上
@Target(ElementType.TYPE)//retention/retentionPolicy(保留)注解,在编译的时候会被保留在某个(那个)特定的编译阶段
//这种类型的Annotations将被JVM保留
@Retention(RetentionPolicy.RUNTIME)//表明这个注解@documented会被javac工具记录
@Documented//组合注解
//组合configuration元注解
@Configuration
//组合ComponentScan元注解
@ComponentScan//组合注解
public @interface WiselyConfiguration {//覆盖value参数
String[] value() default{};}

  

package ch2.annotation;import org.springframework.stereotype.Service;//声明为spring的组件
@Service//演示服务Bean
public class DemoService {public void outputResult()
{
System.out.println("从组合注解配置里,照样获得Bean");
}}

  

package ch2.annotation;//引入ch2.annotation下的包
//使用wiselyConfiguration组合注解代替@ComponentScan,@Configuration
@WiselyConfiguration("ch2.annotation")//新的配置类
public class DemoConfig {}

  

package ch2.annotation;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class Main {public static void main(String[] args)
{AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class);
DemoService demoService = context.getBean(DemoService.class);
demoService.outputResult();
context.close();}}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,906
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,739
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,492
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,130
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,293