SPRING

spring注解开发AnnotationConfigApplicationContext的使用

使用AnnotationConfigApplicationContext可以实现基于Java的配置类加载Spring的应用上下文。避免使用application.xml进行配置。相比XML配置,更加便捷。pom引入依赖:org.springframeworkspring-context5.1.7.RELEASEAppConfig.javapackage com.kaigejava.con

使用AnnotationConfigApplicationContext可以实现基于Java的配置类加载Spring的应用上下文。避免使用application.xml进行配置。相比XML配置,更加便捷。

pom引入依赖:

org.springframeworkspring-context5.1.7.RELEASE

AppConfig.java

package com.kaigejava.config;

import com.kaigejava.Entitlement;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {
    @Bean(name="entitlement")
    public Entitlement entitlement() {
        Entitlement ent= new Entitlement();
        ent.setName("Entitlement");
        ent.setTime(1);
        return ent;
    }

    

原创不易,完成人机校验,阅读全文

相关推荐