[关闭]
@EggGump 2018-07-02T15:47:47.000000Z 字数 793 阅读 423

Spring注解

spring,maven相关


bean

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://www.springframework.org/schema/beans
  4. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  5. <bean id="helloBean" class="com.yiibai.hello.impl.HelloWorldImpl">
  6. </beans>

等效于以下JavaConfig的配置:

  1. import org.springframework.context.annotation.Bean;
  2. import org.springframework.context.annotation.Configuration;
  3. import com.yiibai.hello.HelloWorld;
  4. import com.yiibai.hello.impl.HelloWorldImpl;
  5. /* http://www.manongjc.com/article/1603.html */
  6. @Configuration
  7. public class AppConfig {
  8. @Bean(name="helloBean")
  9. public HelloWorld helloWorld() {
  10. return new HelloWorldImpl();
  11. }
  12. }

context这样写

  1. ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注