- 浏览: 56221 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (93)
- java (3)
- ios (9)
- wp (15)
- android (0)
- js (1)
- 服务器 (0)
- db (0)
- linux (1)
- python (0)
- xcode (0)
- ide (2)
- maven (0)
- spring (0)
- sql (0)
- 第三方 (1)
- nexus (0)
- nginx (11)
- tomcat (0)
- jenkins (0)
- zookeeper (1)
- git (1)
- svn (0)
- uml (0)
- redis (4)
- activemq (1)
- flume (0)
- kafka (0)
- mysql (1)
- memcached (0)
- mybatis (0)
- mac (0)
- mongo (1)
- docker (6)
- cache (0)
- jvm (0)
- markdown (0)
- springboot (24)
- mycat (3)
- LTS (3)
- 运维 (0)
- opts (1)
- netty (1)
- tcc (0)
- ffmpeg (2)
- 直播 (6)
- cxf (0)
- nodejs (0)
- storm (0)
- elasticjob (0)
- php (0)
最新评论
Configuration:减少xml中配置,可以生命一个配置类来对bean进行配置
=======================================================
SpringConfig.java
============================
package org.spring.springboot.configs;
import org.spring.springboot.web.Student;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringConfig {
@Bean(name = "StudentBean")
public Student student(){
Student s = new Student();
s.setName("studentBean");
return s;
}
@Bean(name = "StudentsBean")
public Student students(@Qualifier("StudentBean")Student student){
return student;
}
}
============================
EnviromentConfig.java
通过EnvironmentAware 获取env 来读取properties
============================
@Configuration
public class EnviromentConfig implements EnvironmentAware{
private RelaxedPropertyResolver propertyResolver;
/**
* 这个方法只是测试实现EnvironmentAware接口,读取环境变量的方法。
*/
@Override
public void setEnvironment(Environment env) {
String str = env.getProperty("server.port");
System.out.println(str);
propertyResolver = new RelaxedPropertyResolver(env, "server.");
String value = propertyResolver.getProperty("port");
System.out.println(value);
}
}
============================
Controller中调用
============================
@Resource(name = "StudentBean")
private Student studentBean;
@Resource(name = "StudentsBean")
private Student studentsBean;
@RequestMapping("/say")
public String sayHello() {
System.out.println(studentBean.getName());
System.out.println(studentsBean.getName());
return "Hello,World111!";
}
=======================================================
SpringConfig.java
============================
package org.spring.springboot.configs;
import org.spring.springboot.web.Student;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringConfig {
@Bean(name = "StudentBean")
public Student student(){
Student s = new Student();
s.setName("studentBean");
return s;
}
@Bean(name = "StudentsBean")
public Student students(@Qualifier("StudentBean")Student student){
return student;
}
}
============================
EnviromentConfig.java
通过EnvironmentAware 获取env 来读取properties
============================
@Configuration
public class EnviromentConfig implements EnvironmentAware{
private RelaxedPropertyResolver propertyResolver;
/**
* 这个方法只是测试实现EnvironmentAware接口,读取环境变量的方法。
*/
@Override
public void setEnvironment(Environment env) {
String str = env.getProperty("server.port");
System.out.println(str);
propertyResolver = new RelaxedPropertyResolver(env, "server.");
String value = propertyResolver.getProperty("port");
System.out.println(value);
}
}
============================
Controller中调用
============================
@Resource(name = "StudentBean")
private Student studentBean;
@Resource(name = "StudentsBean")
private Student studentsBean;
@RequestMapping("/say")
public String sayHello() {
System.out.println(studentBean.getName());
System.out.println(studentsBean.getName());
return "Hello,World111!";
}
发表评论
-
springboot:condition
2017-07-26 11:10 326public class LinuxCondition imp ... -
springboot:tomcat启动
2017-07-20 15:02 8841.在pom.xml里设置 <packaging> ... -
springboot:shiro
2017-07-13 15:52 920第一次学习系统学习shiro 并将shiro集成到sprin ... -
springboot:upload
2017-07-06 10:25 708FileUploadConfiguration.java == ... -
springboot:servlet
2017-07-06 10:17 463Application.java ============== ... -
springboot:freemarker
2017-07-05 17:33 480pom.xml ======================= ... -
springboot:task
2017-07-05 12:11 397TaskPool.java ================= ... -
springboot:热部署
2017-07-05 11:23 318pom.xml: ====================== ... -
springboot:注解
2017-07-04 11:36 574@EnableAutoConfiguration注解 excl ... -
springboot:server属性配置
2017-07-04 10:05 676server配置 ====================== ... -
springboot:memcached
2017-07-03 17:23 865pom.xml ======================= ... -
springboot:health
2017-07-03 16:43 353<dependency> ... -
springboot:mongodb
2017-07-03 15:38 1525pom.xml ======================= ... -
springboot:quartz集群
2017-07-02 20:40 956pom.xml ======================= ... -
springboot:ControllerAdvice
2017-07-02 14:09 340全局异常拦截 //@ControllerAdvice(anno ... -
springboot:dubbo
2017-07-02 10:40 467server: ======================= ... -
springboot:amq
2017-07-01 22:20 431pom.xml ======================= ... -
springboot:redis(jedis)
2017-07-01 14:10 871application.properties ======== ... -
springboot:mybatis&druid&pagehelper
2017-07-01 13:35 368=============================== ... -
springboot:logback
2017-06-30 16:20 488=============================== ...
相关推荐
主要介绍了springboot @Configuration @bean注解作用解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
#学习springboot自动装配 ##一,手动装配 ### 1,模式注解装配 @Component注解,或者@Component注解的扩展,@ Controller,@ ...注意:@Configuration注解的配置类有如下要求: @Configuration不可以是final类型;
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
datasource.setURL("jdbc:oracle:thin:@localhost:1521/orcl"); return datasource; } } 4,springboot与普通项目特殊的jar 4.1,spring-boot-starter-jdbc,可能需要用来替换spring-jdbc 4.2,ojdbc,...
@Configuration :将类标记为应用程序上下文的bean定义的源 @EnableAutoConfiguration :告诉Spring引导开始基于类路径和其他bean添加bean。 例如,如果spring-webmvc在类路径上,则将激活关键的web-application-...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...
2,使编码变得简单,SpringBoot采用 JavaConfig的方式对Spring进行配置,并且提供了大量的注解,极大的提高了工作效率,比如@Configuration和@bean注解结合,基于@Configuration完成类扫描,基于@bean注解把返回值...