@SpringBootApplication
public class SpringBootSampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootSampleApplication.class, args);
}
}
@SpringBootApplication()
public class SpringBootSampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootSampleApplication.class, args);
}
}
@SpringBootApplication()
public class SpringBootSampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(SpringBootSampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
}
public class MyAppListener implements ApplicationListener {
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
System.out.println("应用程序准备就绪");
}
}
在监听器中可以设置下面几种事件。
ApplicationStartingEvent
ApplicationEnvironmentPreparedEvent
ApplicationPreparedEvent
ApplicationReadyEvent
ApplicationFailedEvent
之后,把监听器添加到Spring程序中。
@SpringBootApplication()
public class SpringBootSampleApplication {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(SpringBootSampleApplication.class);
application.setBannerMode(Banner.Mode.OFF);
application.addListeners(new MyAppListener());
application.run(args);
}
}
spring:
output:
ansi:
enabled: always
thymeleaf:
cache: false
profiles:
include:
- product
- test
active: test
如果需要多个Profile,YAML只需要一个文件即可,profiles之间使用---分隔开。
server:
address: 192.168.1.100
---
spring:
profiles: development
server:
address: 127.0.0.1
---
spring:
profiles: production
server:
address: 192.168.1.120
使用Properties还是YAML,根据个人喜好即可。
自动配置
修改自动配置
Spring Boot的核心就是自动配置,它为几乎所有的Spring组件都提供了相应的自动配置类,而且默认是打开的。所以只要相关的jar文件存在,这些自动配置就会被使用。其中有些配置属于必配的(例如Web模板),自动配置会为我们省下不少时间;有些配置(例如数据源)则往往需要我们修改。Spring的自动配置是非侵入式的,所以如果我们声明了自己的数据源,那么Spring自动配置的嵌入式数据源就会取消。
当然如果想要关闭某些自动配置也是可以的。如果你有自己的主配置类,手动在上排除某些自动配置类即可。
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}
自动注册指的是,只需要在Spring中注册相应类型的Bean。Spring Web MVC会自动识别和使用这些Bean。例如,我们要添加新的HttpMessageConverter,只需要向下面这样。
@Configuration
public class MyConfiguration {
@Bean
public HttpMessageConverters customConverters() {
HttpMessageConverter> additional = ...
HttpMessageConverter> another = ...
return new HttpMessageConverters(additional, another);
}
}
现实生活中,有些工作是需要团队中成员依次完成的,这就涉及到了一个顺序问题。现在有T1、T2、T3三个工人,如何保证T2在T1执行完后执行,T3在T2执行完后执行?问题分析:首先问题中有三个实体,T1、T2、T3, 因为是多线程编程,所以都要设计成线程类。关键是怎么保证线程能依次执行完呢?
Java实现过程如下:
public class T1 implements Runnabl
hive在使用having count()是,不支持去重计数
hive (default)> select imei from t_test_phonenum where ds=20150701 group by imei having count(distinct phone_num)>1 limit 10;
FAILED: SemanticExcep
转载源:http://blog.sina.com.cn/s/blog_4f925fc30100rx5l.html
mysql -uroot -p
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@centos var]# service mysql
#mq
xdr.mq.url=tcp://192.168.100.15:61618;
import java.io.IOException;
import java.util.Properties;
public class Test {
String conf = "log4j.properties";
private static final
有一个工程,本来运行是正常的,我想把它移植到另一台PC上,结果报:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobovip.bgr/com.mobovip.bgr.MainActivity}: java.lang.ClassNotFoundException: Didn't f
// 报错如下:
$ git pull origin master
fatal: unable to access 'https://git.xxx.com/': SSL certificate problem: unable to get local issuer ce
rtificate
// 原因:
由于git最新版默认使用ssl安全验证,但是我们是使用的git未设