In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
一:
package com.zcp.springstart2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
@SpringBootApplication
public class App {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
System.out.println(System.getProperty("file.encoding"));
System.out.println(context.getBeansOfType(EncodingConvert.class));
System.out.println(">>>>>>>>>>>>>start>>>>>>>>>>>>");
System.out.println(context.getBeansOfType(Runnable.class));
System.out.println(">>>>>>>>>>>>>end>>>>>>>>>>>>");
context.close();
}
}
接口:
package com.zcp.springstart2;
public interface EncodingConvert {
}
接口的实现:
package com.zcp.springstart2;
public class UTF8EncodingConvert implements EncodingConvert {
}
package com.zcp.springstart2;
public class GBKEncodingConvert implements EncodingConvert {
}
package com.zcp.springstart2;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class GBKCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String encoding = System.getProperty("file.encoding");
if(null != encoding){
return "gbk".equals(encoding.toLowerCase());
}
return false;
}
}
package com.zcp.springstart2;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
public class UTF8Condition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
String encoding = System.getProperty("file.encoding");
if(null != encoding){
return "utf-8".equals(encoding.toLowerCase());
}
return false;
}
}
常用的conditional的使用:
package com.zcp.springstart2;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
@SpringBootConfiguration
public class UserConfig {
@Bean
@ConditionalOnProperty(name="runnable.enabled",havingValue="true",matchIfMissing=true)
public Runnable createRunnable(){
return new Runnable() {
@Override
public void run() {
System.out.println("UserConfig中的Runnable");
}
};
}
@Bean
@ConditionalOnClass(name="com.zcp.springstart2.User")
public Runnable createRunnableOnClass(){
return new Runnable() {
@Override
public void run() {
System.out.println("UserConfig中的createRunnableOnBean");
}
};
}
@Bean
@ConditionalOnBean(name="user")
public Runnable createRunnableOnBean(){
return new Runnable() {
@Override
public void run() {
System.out.println("UserConfig中的createRunnableOnBean");
}
};
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.