1从spring4.0以后,@Spring boot Application就包含了@ComponentScan,@ComponentScan就不用写了

2@MapperScan(basePackages = "com.xlbshiro.shirodemo.mapper")--扫描持久层接口,这个注解@SpringBootApplication没有包含他

从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplicationContext或AnnotationConfigWebApplicationContext类进行扫描,并用于构建bean定义,初始化Spring容器。

注意:@Configuration注解的配置类有如下要求:

  1. @Configuration不可以是final类型;
  2. @Configuration不可以是匿名类;
  3. 嵌套的configuration必须是静态类。

一、用@Configuration加载spring
1.1、@Configuration配置spring并启动spring容器
1.2、@Configuration启动容器+@Bean注册Bean
1.3、@Configuration启动容器+@Component注册Bean
1.4、使用 AnnotationConfigApplicationContext 注册 AppContext 类的两种方法
1.5、配置Web应用程序(web.xml中配置AnnotationConfigApplicationContext)

二、组合多个配置类
2.1、在@configuration中引入spring的xml配置文件
2.2、在@configuration中引入其它注解配置
2.3、@configuration嵌套(嵌套的Configuration必须是静态类)
三、@EnableXXX注解
四、@Profile逻辑组配置
五、使用外部变量

一、@Configuation加载Spring方法

1.1、@Configuration配置spring并启动spring容器

@Configuration标注在类上,相当于把该类作为spring的xml配置文件中的<beans>,作用为:配置spring容器(应用上下文)

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.annotation.Configuration;
  4.  
  5. @Configuration
  6. public class TestConfiguration {
  7. public TestConfiguration() {
  8. System.out.println("TestConfiguration容器启动初始化。。。");
  9. }
  10. }

相当于:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  4. xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  5. xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
  8. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
  9. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
  10. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
  11. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd
  12. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd" default-lazy-init="false">
  13.  
  14. </beans>

主方法进行测试:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. public class TestMain {
  7. public static void main(String[] args) {
  8.  
  9. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  10. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  11.  
  12. // 如果加载spring-context.xml文件:
  13. // ApplicationContext context = new
  14. // ClassPathXmlApplicationContext("spring-context.xml");
  15. }
  16. }

从运行主方法结果可以看出,spring容器已经启动了:

1.2、@Configuration启动容器+@Bean注册Bean,@Bean下管理bean的生命周期

@Bean标注在方法上(返回某个实例的方法),等价于spring的xml配置文件中的<bean>,作用为:注册bean对象

bean类:

  1. package com.dxz.demo.configuration;
  2.  
  3. public class TestBean {
  4.  
  5. private String username;
  6. private String url;
  7. private String password;
  8.  
  9. public void sayHello() {
  10. System.out.println("TestBean sayHello...");
  11. }
  12.  
  13. public String toString() {
  14. return "username:" + this.username + ",url:" + this.url + ",password:" + this.password;
  15. }
  16.  
  17. public void start() {
  18. System.out.println("TestBean 初始化。。。");
  19. }
  20.  
  21. public void cleanUp() {
  22. System.out.println("TestBean 销毁。。。");
  23. }
  24. }

配置类:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.context.annotation.Scope;
  6.  
  7. @Configuration
  8. public class TestConfiguration {
  9. public TestConfiguration() {
  10. System.out.println("TestConfiguration容器启动初始化。。。");
  11. }
  12.  
  13. // @Bean注解注册bean,同时可以指定初始化和销毁方法
  14. // @Bean(name="testBean",initMethod="start",destroyMethod="cleanUp")
  15. @Bean
  16. @Scope("prototype")
  17. public TestBean testBean() {
  18. return new TestBean();
  19. }
  20. }

主方法测试类:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. public class TestMain {
  7. public static void main(String[] args) {
  8.  
  9. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  10. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  11.  
  12. // 如果加载spring-context.xml文件:
  13. // ApplicationContext context = new
  14. // ClassPathXmlApplicationContext("spring-context.xml");
  15.  
  16. //获取bean
  17. TestBean tb = (TestBean) context.getBean("testBean");
  18. tb.sayHello();
  19. }
  20. }

结果:

注: 
(1)、@Bean注解在返回实例的方法上,如果未通过@Bean指定bean的名称,则默认与标注的方法名相同; 
(2)、@Bean注解默认作用域为单例singleton作用域,可通过@Scope(“prototype”)设置为原型作用域; 
(3)、既然@Bean的作用是注册bean对象,那么完全可以使用@Component、@Controller、@Service、@Ripository等注解注册bean,当然需要配置@ComponentScan注解进行自动扫描。

@Bean下管理bean的生命周期

可以使用基于 Java 的配置来管理 bean 的生命周期。@Bean 支持两种属性,即 initMethod 和destroyMethod,这些属性可用于定义生命周期方法。在实例化 bean 或即将销毁它时,容器便可调用生命周期方法。生命周期方法也称为回调方法,因为它将由容器调用。使用 @Bean 注释注册的 bean 也支持 JSR-250 规定的标准 @PostConstruct 和 @PreDestroy 注释。如果您正在使用 XML 方法来定义 bean,那么就应该使用 bean 元素来定义生命周期回调方法。以下代码显示了在 XML 配置中通常使用 bean 元素定义回调的方法。

  1. @Configuration
  2. @ComponentScan(basePackages = "com.dxz.demo.configuration")
  3. public class TestConfiguration {
  4. public TestConfiguration() {
  5. System.out.println("TestConfiguration容器启动初始化。。。");
  6. }
  7.  
  8. //@Bean注解注册bean,同时可以指定初始化和销毁方法
  9. @Bean(name="testBean",initMethod="start",destroyMethod="cleanUp")
  10. @Scope("prototype")
  11. public TestBean testBean() {
  12. return new TestBean();
  13. }
  14. }

启动类:

  1. public class TestMain {
  2. public static void main(String[] args) {
  3.  
  4. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  5.  
  6. TestBean tb = (TestBean) context.getBean("testBean");
  7. tb.sayHello();
  8. System.out.println(tb);
  9.  
  10. TestBean tb2 = (TestBean) context.getBean("testBean");
  11. tb2.sayHello();
  12. System.out.println(tb2);
  13. }
  14. }

结果:

分析:

结果中的1:表明initMethod生效

结果中的2:表明@Scope(“prototype”)生效

1.3、@Configuration启动容器+@Component注册Bean

bean类:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.stereotype.Component;
  4.  
  5. //添加注册bean的注解
  6. @Component
  7. public class TestBean {
  8.  
  9. private String username;
  10. private String url;
  11. private String password;
  12.  
  13. public void sayHello() {
  14. System.out.println("TestBean sayHello...");
  15. }
  16.  
  17. public String toString() {
  18. return "username:" + this.username + ",url:" + this.url + ",password:" + this.password;
  19. }
  20.  
  21. public void start() {
  22. System.out.println("TestBean 初始化。。。");
  23. }
  24.  
  25. public void cleanUp() {
  26. System.out.println("TestBean 销毁。。。");
  27. }
  28. }

配置类:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.ComponentScan;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.context.annotation.Scope;
  7.  
  8. @Configuration
  9. //添加自动扫描注解,basePackages为TestBean包路径
  10. @ComponentScan(basePackages = "com.dxz.demo.configuration")
  11. public class TestConfiguration {
  12. public TestConfiguration() {
  13. System.out.println("TestConfiguration容器启动初始化。。。");
  14. }
  15.  
  16. /*// @Bean注解注册bean,同时可以指定初始化和销毁方法
  17. // @Bean(name="testNean",initMethod="start",destroyMethod="cleanUp")
  18. @Bean
  19. @Scope("prototype")
  20. public TestBean testBean() {
  21. return new TestBean();
  22. }*/
  23. }

主方法测试获取bean对象:

  1. package com.dxz.demo.configuration;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. public class TestMain {
  7. public static void main(String[] args) {
  8.  
  9. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  10. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  11.  
  12. // 如果加载spring-context.xml文件:
  13. // ApplicationContext context = new
  14. // ClassPathXmlApplicationContext("spring-context.xml");
  15.  
  16. //获取bean
  17. TestBean tb = (TestBean) context.getBean("testBean");
  18. tb.sayHello();
  19. }
  20. }

sayHello()方法都被正常调用。

1.4、使用 AnnotationConfigApplicationContext 注册 AppContext 类的两种方法

1.4.1、 配置类的注册方式是将其传递给 AnnotationConfigApplicationContext 构造函数

  1. public static void main(String[] args) {
  2.  
  3. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  4. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  5.  
  6. //获取bean
  7. TestBean tb = (TestBean) context.getBean("testBean");
  8. tb.sayHello();
  9. }

1.4.2、 AnnotationConfigApplicationContext 的register 方法传入配置类来注册配置类

  1. public static void main(String[] args) {
  2. ApplicationContext ctx = new AnnotationConfigApplicationContext();
  3. ctx.register(AppContext.class)
  4. }

1.5、配置Web应用程序(web.xml中配置AnnotationConfigApplicationContext)

过去,您通常要利用 XmlWebApplicationContext 上下文来配置 Spring Web 应用程序,即在 Web 部署描述符文件 web.xml 中指定外部 XML 上下文文件的路径。XMLWebApplicationContext 是 Web 应用程序使用的默认上下文类。以下代码描述了 web.xml 中指向将由 ContextLoaderListener 监听器类载入的外部 XML 上下文文件的元素。

  1. <web-app>
  2. <context-param>
  3. <param-name>contextConfigLocation</param-name>
  4. <param-value>/WEB-INF/applicationContext.xml</param-value>
  5. </context-param>
  6. <listener>
  7. <listener-class>
  8. org.springframework.web.context.ContextLoaderListener
  9. </listener-class>
  10. </listener>
  11. <servlet>
  12. <servlet-name>sampleServlet</servlet-name>
  13. <servlet-class>
  14. org.springframework.web.servlet.DispatcherServlet
  15. </servlet-class>
  16. </servlet>
  17.  
  18. ...
  19. </web-app>

现在,您要将 web.xml 中的上述代码更改为使用 AnnotationConfigApplicationContext 类。切记,XmlWebApplicationContext 是 Spring 为 Web 应用程序使用的默认上下文实现,因此您永远不必在您的web.xml 文件中显式指定这个上下文类。现在,您将使用基于 Java 的配置,因此在配置 Web 应用程序时,需要在web.xml 文件中指定 AnnotationConfigApplicationContext 类。上述代码将修改如下:

  1. <web-app>
  2. <context-param>
  3. <param-name>contextClass</param-name>
  4. <param-value>
  5. org.springframework.web.context.
  6. support.AnnotationConfigWebApplicationContext
  7. </param-value>
  8. </context-param>
  9. <context-param>
  10. <param-name>contextConfigLocation</param-name>
  11. <param-value>
  12. demo.AppContext
  13. </param-value>
  14. </context-param>
  15. <listener>
  16. <listener-class>
  17. org.springframework.web.context.ContextLoaderListener
  18. </listener-class>
  19. </listener>
  20. <servlet>
  21. <servlet-name>sampleServlet</servlet-name>
  22. <servlet-class>
  23. org.springframework.web.servlet.DispatcherServlet
  24. </servlet-class>
  25. <init-param>
  26. <param-name>contextClass</param-name>
  27. <param-value>
  28. org.springframework.web.context.
  29. support.AnnotationConfigWebApplicationContext
  30. </param-value>
  31. </init-param>
  32. </servlet>
  33.  
  34. ...
  35. </web-app>

以上修改后的 web.xml 现在定义了 AnnotationConfigWebApplicationContext 上下文类,并将其作为上下文参数和 servlet 元素的一部分。上下文配置位置现在指向 AppContext 配置类。这非常简单。下一节将演示 bean 的生命周期回调和范围的实现。

1.6、@Configuation总结

@Configuation等价于<Beans></Beans>

@Bean等价于<Bean></Bean>

@ComponentScan等价于<context:component-scan base-package=”com.dxz.demo”/>

二、组合多个配置类

2.1、在@configuration中引入spring的xml配置文件

  1. package com.dxz.demo.configuration2;
  2.  
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.context.annotation.ImportResource;
  5.  
  6. @Configuration
  7. @ImportResource("classpath:applicationContext-configuration.xml")
  8. public class WebConfig {
  9. }

bean类:

  1. package com.dxz.demo.configuration2;
  2.  
  3. public class TestBean2 {
  4. private String username;
  5. private String url;
  6. private String password;
  7.  
  8. public void sayHello() {
  9. System.out.println("TestBean2 sayHello...");
  10. }
  11.  
  12. public String toString() {
  13. return "TestBean2 username:" + this.username + ",url:" + this.url + ",password:" + this.password;
  14. }
  15.  
  16. public void start() {
  17. System.out.println("TestBean2 初始化。。。");
  18. }
  19.  
  20. public void cleanUp() {
  21. System.out.println("TestBean2 销毁。。。");
  22. }
  23. }

测试类:

  1. package com.dxz.demo.configuration2;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. public class TestMain2 {
  7. public static void main(String[] args) {
  8.  
  9. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  10. ApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class);
  11.  
  12. // 如果加载spring-context.xml文件:
  13. // ApplicationContext context = new
  14. // ClassPathXmlApplicationContext("spring-context.xml");
  15.  
  16. // 获取bean
  17. TestBean2 tb = (TestBean2) context.getBean("testBean2");
  18. tb.sayHello();
  19. }
  20. }

结果:

2.2、在@configuration中引入其它注解配置

  1. package com.dxz.demo.configuration2;
  2.  
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.context.annotation.Import;
  5. import org.springframework.context.annotation.ImportResource;
  6.  
  7. import com.dxz.demo.configuration.TestConfiguration;
  8.  
  9. @Configuration
  10. @ImportResource("classpath:applicationContext-configuration.xml")
  11. @Import(TestConfiguration.class)
  12. public class WebConfig {
  13. }

测试类:

  1. package com.dxz.demo.configuration2;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. import com.dxz.demo.configuration.TestBean;
  7.  
  8. public class TestMain2 {
  9. public static void main(String[] args) {
  10.  
  11. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContext
  12. ApplicationContext context = new AnnotationConfigApplicationContext(WebConfig.class);
  13.  
  14. // 如果加载spring-context.xml文件:
  15. // ApplicationContext context = new
  16. // ClassPathXmlApplicationContext("spring-context.xml");
  17.  
  18. // 获取bean
  19. TestBean2 tb2 = (TestBean2) context.getBean("testBean2");
  20. tb2.sayHello();
  21.  
  22. TestBean tb = (TestBean) context.getBean("testBean");
  23. tb.sayHello();
  24. }
  25. }

结果:

2.3、@configuration嵌套(嵌套的Configuration必须是静态类)

通过配置类嵌套的配置类,达到组合多个配置类的目的。但注意内部类必须是静态类。

上代码:

  1. package com.dxz.demo.configuration3;
  2.  
  3. import org.springframework.stereotype.Component;
  4.  
  5. @Component
  6. public class TestBean {
  7.  
  8. private String username;
  9. private String url;
  10. private String password;
  11.  
  12. public void sayHello() {
  13. System.out.println("TestBean sayHello...");
  14. }
  15.  
  16. public String toString() {
  17. return "username:" + this.username + ",url:" + this.url + ",password:" + this.password;
  18. }
  19.  
  20. public void start() {
  21. System.out.println("TestBean start");
  22. }
  23.  
  24. public void cleanUp() {
  25. System.out.println("TestBean destory");
  26. }
  27. }
  1. package com.dxz.demo.configuration3;
  2.  
  3. public class DataSource {
  4.  
  5. private String dbUser;
  6. private String dbPass;
  7. public String getDbUser() {
  8. return dbUser;
  9. }
  10. public void setDbUser(String dbUser) {
  11. this.dbUser = dbUser;
  12. }
  13. public String getDbPass() {
  14. return dbPass;
  15. }
  16. public void setDbPass(String dbPass) {
  17. this.dbPass = dbPass;
  18. }
  19. @Override
  20. public String toString() {
  21. return "DataSource [dbUser=" + dbUser + ", dbPass=" + dbPass + "]";
  22. }
  23. }

配置类:

  1. package com.dxz.demo.configuration3;
  2.  
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.ComponentScan;
  5. import org.springframework.context.annotation.Configuration;
  6.  
  7. @Configuration
  8. @ComponentScan(basePackages = "com.dxz.demo.configuration3")
  9. public class TestConfiguration {
  10. public TestConfiguration() {
  11. System.out.println("TestConfiguration容器启动初始化。。。");
  12. }
  13.  
  14. @Configuration
  15. static class DatabaseConfig {
  16. @Bean
  17. DataSource dataSource() {
  18. return new DataSource();
  19. }
  20. }
  21. }

启动类:

  1. package com.dxz.demo.configuration3;
  2.  
  3. import org.springframework.context.ApplicationContext;
  4. import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  5.  
  6. public class TestMain {
  7. public static void main(String[] args) {
  8.  
  9. // @Configuration注解的spring容器加载方式,用AnnotationConfigApplicationContext替换ClassPathXmlApplicationContexts
  10. ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
  11.  
  12. //bean
  13. TestBean tb = (TestBean) context.getBean("testBean");
  14. tb.sayHello();
  15.  
  16. DataSource ds = (DataSource) context.getBean("dataSource");
  17. System.out.println(ds);
  18. }
  19. }

结果:

  1. TestConfiguration容器启动初始化。。。
  2. TestBean sayHello...
  3. DataSource [dbUser=null, dbPass=null]

3、@EnableXXX注解

配合@Configuration使用,包括 @EnableAsync, @EnableScheduling, @EnableTransactionManagement, @EnableAspectJAutoProxy, @EnableWebMvc。

@EnableAspectJAutoProxy—《spring AOP 之:@Aspect注解

@EnableScheduling–《Spring 3.1新特性之二:@Enable*注解的源码,spring源码分析之定时任务Scheduled注解

4、@Profile逻辑组配置

见《Spring的@PropertySource + Environment,@PropertySource(PropertySourcesPlaceholderConfigurer)+@Value配合使用

5、使用外部变量

1、@PropertySource + Environment,通过@PropertySource注解将properties配置文件中的值存储到Spring的 Environment中,Environment接口提供方法去读取配置文件中的值,参数是properties文件中定义的key值。
2、@PropertySource(PropertySourcesPlaceholderConfigurer)+@Value

见《Spring的@PropertySource + Environment,@PropertySource(PropertySourcesPlaceholderConfigurer)+@Value配合使用

@Configuration的使用 和作用的更多相关文章

  1. @Configuration的使用 和作用(转)

    从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法,这些方法将会被AnnotationConfigApplic ...

  2. hibernate中Configuration类的作用

    问题:我们在获得一个SessionFactory对象的时候经常是写下面这行代码: SessionFactory sessionFactory = new Configuration().configu ...

  3. Configuration对象

    Configuration对象 Hibernate的持久化操作离不开SessionFactory对象,使用该对象的openSession()方法可以打开Session对象.而SessionFactor ...

  4. 5 -- Hibernate的基本用法 --4 1 创建Configuration对象

    org.hibernate.cfg.Configuration实例代表了应用程序到SQL数据库的配置信息,Configuration对象提供了一个buildSessionFactory()方法,该方法 ...

  5. Spring源码解析之@Configuration

    @Configuration简介 用于标识一个类为配置类,与xml配置效果类似 用法简介 public class TestApplication { public static void main( ...

  6. SpringBoot自动装配原理之Configuration以及@Bean注解的使用

    Configuration以及Bean注解的使用 该知识点在Spring中应该学过,没有学过或者遗忘的的朋友需要预习或温习前置知识点.SpringBoot其实就是Spring的进一步简化,所以前置知识 ...

  7. jvm系列(四):jvm调优-命令大全(jps jstat jmap jhat jstack jinfo)

    文章同步发布于github博客地址,阅读效果更佳,欢迎品尝 运用jvm自带的命令可以方便的在生产监控和打印堆栈的日志信息帮忙我们来定位问题!虽然jvm调优成熟的工具已经有很多:jconsole.大名鼎 ...

  8. Dozer扫盲级教程

    前言 这篇文章是本人在阅读Dozer官方文档(5.5.1版本,官网已经一年多没更新了)的过程中,整理下来我认为比较基础的应用场景. 本文中提到的例子应该能覆盖JavaBean映射的大部分场景,希望对你 ...

  9. maven常用插件: 打包源码 / 跳过测试 / 单独打包依赖项

    一.指定编译文件的编码 maven-compile-plugin <plugin> <groupId>org.apache.maven.plugins</groupId& ...

随机推荐

  1. js code

    //在页面增加一个放置图标的区块 if(!document.getElementById('_span_jiucuo')) document.write("<span id='_spa ...

  2. 字符串函数 mysql 和sqlserver 中对于字符串的常用函数和区别

    1. 对于字符串大小写的统一 mysql和sqlserver中都有同名函数lower()和upper(),但是mysql中还有另外一对函数,达到同样的目的,lcase()和ucase(),也就是英文中 ...

  3. [转]VS中的路径宏 OutDir、ProjectDir、SolutionDir各种路径含义

    转自 http://blog.csdn.net/restraint/article/details/39934401 说明 $(RemoteMachine) 设置为“调试”属性页上“远程计算机”属性的 ...

  4. WCF 一步一步 发布 WCF服务 到 IIS (图)

    WCF 一步一步 发布 WCF服务 到 IIS (图) 使用VS自带的WCFSVCHost(WCF服务主机)发布WCF服务,时刻开发人员测试使用. 下面我们来看一下如何在IIS中部发布一个WCF服务. ...

  5. C#如何实现类似QQ那样靠边隐藏的功能

    http://www.cnblogs.com/yechensi/archive/2009/08/02/1537145.html C#如何实现类似QQ那样靠边隐藏的功能 你想过为自己的程序添加靠边隐藏的 ...

  6. LeetCode--415--字符串相加

    问题描述: 给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和. 注意: num1 和num2 的长度都小于 5100. num1 和num2 都只包含数字 0-9. num1 和nu ...

  7. p1459 Sorting a Three-Valued Sequence

    如果将1和3都放到正确的位置,2自然也在正确的位置.那么统计1,2,3的数量num1,num2,num3.再看前num1个数有几个(设x个)不是1,那么x个1肯定要移.设前num1个数有y个3,最后n ...

  8. android ------- 运行官方NDK 案例HelloJNI

    下载案例 HelloJNI ,导入工程到Eclipse,  可以直接下载我的案例, 源码下载:https://github.com/DickyQie/android-ndk 目录图 使用命令生成  . ...

  9. [LintCode] Number of Islands(岛屿个数)

    描述 给一个01矩阵,求不同的岛屿的个数. 0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛.我们只考虑上下左右为相邻. 样例 在矩阵: [ [1, 1, 0, 0, 0], [0, 1, ...

  10. Vrrp和Hsrp的区别

    VRRP原理协议简述简单来说,VRRP是一种容错协议,它为具有组播或广播能力的局域网(如以太网)设计,它保证当局域网内主机的下一跳路由器出现故障时,可以及时的由另一台路由器来代替,从而保持通讯的连续性 ...