@Configuration
@Profile("production")
public class ProductionConfiguration {
// ...
}
在application.properties中的参数可以项目使用,比如: app.name=MyApp app.description=${app.name} is a Spring Boot application 3. Type-safe Configuration Properties 使用@Value("${property}")来依赖注入属性有时候会很麻烦,尤其是多个属性需要注入。Spring-boot提供一种更加方便的方式@ConfigurationProperties。 首先建立一个类
@ConfigurationProperties(prefix="connection")
public class ConnectionProperties {
private String username;
private InetAddress remoteAddress;
// ... getters and setters
}
在@EnableConfigurationProperties中指定建立的配置类
@Configuration
@EnableConfigurationProperties(ConnectionProperties.class)
public class MyConfiguration {
}
Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
Support for serving static resources, including support for WebJars (see below).
Automatic registration of Converter, GenericConverter, Formatter beans.
Support for HttpMessageConverters (see below).
Automatic registration of MessageCodesResolver (see below).
Static index.html support.
Custom Favicon support.
Automatic use of a ConfigurableWebBindingInitializer bean (see below). 如果你想要配置spring mvc 的一些拦截器, formatters, view controllers等等,你可以创建一个类继承于WebMvcConfigurerAdapter;例如:自己配置一个拦截器
@Configuration @ComponentScan(basePackages = "com.spring.boot.controller3") public class WebConfigure extends WebMvcConfigurerAdapter { @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LogInterceptor()).addPathPatterns("/user/**"); } }
@Configuration
public class MyConfiguration {
@Bean
public HttpMessageConverters customConverters() {
HttpMessageConverter> additional = ...
HttpMessageConverter> another = ...
return new HttpMessageConverters(additional, another);
}
}
2. Static Content(静态资源)
默认情况下Spring-boot使用的是Spring-mvc中的ResourceHttpRequestHandler来处理静态资源,默认静态资源的位置是在classpath目录下或者ServletContext根目录下的/static (or /public or /resources or/META-INF/resources);你也可以添加自己的处理方式,通过使用WebMvcConfigurerAdapter中的addResourceHandlers方法。 你也可以自己定义静态资源的位置,使用配置参数spring.resources.staticLocations Spring-boot也支持静态资源缓存,使用版本号,参考spring-boot文档静态资源处理
更多复杂的映射,还可以使用ErrorViewResolver来实现: public class MyErrorViewResolver implements ErrorViewResolver { @Override public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map model) { // Use the request or status to optionally return a ModelAndView return ... } } 我们也可以通过使用springmvc的特性来处理不同的异常,比如:@ExceptionHandler,@ControllerAdvice。其他没有被处理的异常都会被ErrorController拦截处理
@Configuration
public class MyConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/api/**");
}
};
}
}
@Component
public class MyBean {
private final JdbcTemplate jdbcTemplate;
@Autowired
public MyBean(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
// ...
}
3. JPA and ‘Spring Data’
在Spring-boot应用中,可以使用spring-boot-starter-data-jpa作为一个开始,会包含一下依赖: Hibernate — One of the most popular JPA implementations. Spring Data JPA — Makes it easy to implement JPA-based repositories. Spring ORMs — Core ORM support from the Spring Framework. 3.1 Entity Classes And Spring Data JPA Repositories 默认情况下,Spring-boot会扫描主要配置类(有注解@EnableAutoConfiguration or@SpringBootApplication)下面的所有包,任何被@Entity, @Embeddable or @MappedSuperclass注解的类都会作为实体;任何继承了Repository or CrudRepository的接口都会被作为 Repository,不需要任何@Component or Repository 如果你想要自定义寻找的Entity的存放位置,可以使用注解@EntityScan。
好久不来iteye,今天又来看看,哈哈,今天碰到在编码时,反射中会抛出
Illegal overloaded getter method with ambiguous type for propert这么个东东,从字面意思看,是反射在获取getter时迷惑了,然后回想起java在boolean值在生成getter时,分别有is和getter,也许我们的反射对象中就有is开头的方法迷惑了jdk,
泛型
在Java SE 1.5之前,没有泛型的情况的下,通过对类型Object的引用来实现参数的“任意化”,任意化的缺点就是要实行强制转换,这种强制转换可能会带来不安全的隐患
泛型的特点:消除强制转换 确保类型安全 向后兼容
简单泛型的定义:
泛型:就是在类中将其模糊化,在创建对象的时候再具体定义
class fan
安装lua_nginx_module 模块
lua_nginx_module 可以一步步的安装,也可以直接用淘宝的OpenResty
Centos和debian的安装就简单了。。
这里说下freebsd的安装:
fetch http://www.lua.org/ftp/lua-5.1.4.tar.gz
tar zxvf lua-5.1.4.tar.gz
cd lua-5.1.4
ma
public class IsAccendListRecursive {
/*递归判断数组是否升序
* if a Integer array is ascending,return true
* use recursion
*/
public static void main(String[] args){
IsAccendListRecursiv
function init() {
var tt = document.getElementById("tt");
var childNodes = tt.childNodes[0].childNodes;
var level = 0;
for (var i = 0; i < childNodes.length; i++) {
在安装hadoop时,执行JPS出现下面错误
[slave16][email protected]:/tmp/hsperfdata_hdfs# jps
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working