springBoot 시리즈 상용 주해(소결)
3735 단어 springBoot상용 주해
역할:사용자 정의 properties 파일 불 러 오기
사용:@PropertySource(value={"classpath:people.properties"})또는@PropertySource(value="classpath:people.properties")
properties 파일,값 난 장 판 문제 가 져 오기
난 코드 해결:
file ->settings -->file encoding--> 투명 한 native-to-ascill 변환 선택
@ImportResource
역할:spring 의 프로필 을 적용 할 수 있 습 니 다.
사용:사용 클래스 에 ImportResource 주 해 를 추가 합 니 다.예 를 들 어@ImportResource(value="classpath:person.xml")또는@ImportResource(locations={"classpath:person.xml"})
@Conditional
역할:@conditional 이 지정 한 조건 이 성립 되 어야 용기 에 구성 요 소 를 추가 하거나 자동 설정 클래스 를 적용 합 니 다.
이로써 HttpEncoding AutoConfiguration 자동 설정 클래스 예
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ServerProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(CharacterEncodingFilter.class)
@ConditionalOnProperty(prefix = "server.servlet.encoding", value = "enabled", matchIfMissing = true)
public class HttpEncodingAutoConfiguration {
private final Encoding properties;
public HttpEncodingAutoConfiguration(ServerProperties properties) {
this.properties = properties.getServlet().getEncoding();
}
@Bean
@ConditionalOnMissingBean
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
filter.setEncoding(this.properties.getCharset().name());
filter.setForceRequestEncoding(this.properties.shouldForce(Encoding.Type.REQUEST));
filter.setForceResponseEncoding(this.properties.shouldForce(Encoding.Type.RESPONSE));
return filter;
}
@conditionalOnMissingBean:용기 에 CharacterEncoding Filter 가 존재 하지 않 는 다 면 이 bean 은 실례 적 으로 하 나 를 만 들 고 존재 하면 아래 코드 를 가지 않 는 역할 을 합 니 다.@ConditionalOnClass(CharacterEncoding Filter.class):용기 에 CharacterEncoding Filter 라 는 bean(그 중의 한 조건)이 존재 해 야 자동 설정 클래스 HttpEncoding AutoConfiguration 을 실례 화 할 수 있 습 니 다.
@ConditionalOnProperty(prefix="server.servlet.encoding",value="enabled",matchIfMissing=true)는 설정 파일 에 server.servlet.encoding=enabled 가 설정 되 어 있어 야 이 자동 설정 클래스 HttpEncoding AutoConfiguration 을 실례 화 할 수 있 습 니 다.
springBoot 의 모든 자동 설정 클래스 위치:
org\springframework\boot\spring-boot-autoconfigure\2.4.5\spring-boot-autoconfigure-2.4.5.jar!\META-INF\spring.factories 파일 중
spring.factories 이 파일 의 자동 설정 클래스 가 유효 하 다 고 어떻게 판단 합 니까?
yml 또는 application.properties 에서 설정 하면 콘 솔 에서 자동 설정 류 를 인쇄 합 니 다.
######## ##########
debug =true
그 중:Negative match:유효 하지 않 음 을 표시 합 니 다.Positive match:적용 되 는springBoot 시리즈 에 자주 사용 되 는 주해(소결)에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 springBoot 에 자주 사용 되 는 주해 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 조회 하 시기 바 랍 니 다.앞으로 많은 응원 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
springBoot dubbo junit 유닛 테스트의지 하 다 spring boot 시작 클래스 유닛 테스트 클래스...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.