15 Ocak 2018 Pazartesi
11 Ocak 2018 Perşembe
SpringBoot EmbeddedServletContainerCustomizer Arayüzü
Giriş
Şu satırı dahil ederiz.
Projenin şöyle olması gerekir.
Şöyle yaparız.
Şu satırı dahil ederiz.
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
Spring Boot projesine ait bir arayüz. @Configuration veya @SpringBootApplication anotasyonuna sahip bir sınıfın @Bean ile işaretli metodu ile kullanılır.Projenin şöyle olması gerekir.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
setPort metoduŞöyle yaparız.
@Configuration
public class ServletConfig {
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return (container -> {
container.setPort(8012);
});
}
}
26 Aralık 2017 Salı
SpringMVC @EnableWebMvc Anotasyonu
21 Aralık 2017 Perşembe
TransactionSynchronizationManager Sınıfı
Giriş
Şu satırı dahil ederiz
Şu satırı dahil ederiz
import org.springframework.transaction.support.TransactionSynchronizationManager;Açıklaması şöyle.
Şöyle yaparız
Şöyle yaparız
isCurrentTransactionReadOnly metoduCentral helper that manages resources and transaction synchronizations per thread. To be used by resource management code but not by typical application code.
Şöyle yaparız
@Transactional
void foo(){
log.info("Is readonly - " + TransactionSynchronizationManager
.isCurrentTransactionReadOnly());
..
}
getCurrentTransactionName metoduŞöyle yaparız
@Transactional
void foo(){
log.info("Current Transaction Name - " + TransactionSynchronizationManager
.getCurrentTransactionName());
..
}
registerSynchronization metoduregisterSynchronization metodu yazısına taşıdım
setCurrentTransactionName metodu
Şöyle yaparız
@Transactional
void foo(){
TransactionSynchronizationManager.setCurrentTransactionName("TestTransaction");
...
}
20 Aralık 2017 Çarşamba
SpringSecurity HttpSessionSecurityContextRepository Sınıfı
loadContext metodu
SecurityContext nesnesi döner. Şöyle yaparız.
SecurityContext nesnesi döner. Şöyle yaparız.
@Override
public SecurityContext loadContext(HttpRequestResponseHolder requestResponseHolder) {
SecurityContext context = super.loadContext(requestResponseHolder);
Authentication auth = context.getAuthentication();
if (auth instanceof OAuth2Authentication) {
...
}
return context;
}
Etiketler:
HttpSessionSecurityContextRepository,
SpringSecurity
19 Aralık 2017 Salı
SpringBeanAutowiringSupport Sınıfı
Giriş
Soyut bir sınıftır. Spring dışında yaratılan nesnelerin Spring @Autowire anotasyonu ile işaretli alanlarının dolmasını sağlar. Bu sınıftan kalıtan WebApplicationObjectSupport sınıfıdır.
processInjectionBasedOnCurrentContext metodu
Şöyle yaparız.
Soyut bir sınıftır. Spring dışında yaratılan nesnelerin Spring @Autowire anotasyonu ile işaretli alanlarının dolmasını sağlar. Bu sınıftan kalıtan WebApplicationObjectSupport sınıfıdır.
processInjectionBasedOnCurrentContext metodu
Şöyle yaparız.
@PostConstruct
public void init(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
13 Aralık 2017 Çarşamba
SpringContext LinkedMultiValueMap Sınıfı - Multimap
Giriş
Şu satırı dahil ederiz.
Şöyle yaparız.
Elimizde şöyle bir kod olsun.
Şu satırı dahil ederiz.
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
constructorŞöyle yaparız.
MultiValueMap<String, Object> MulMap = new LinkedMultiValueMap<>();
Şöyle yaparız.MultiValueMap<String, Integer> multiValueMap=new LinkedMultiValueMap<>();
add metodu
Elimizde şöyle bir kod olsun.
MultiValueMap<String, String> headers; new LinkedMultiValueMap<>();
Şöyle yaparız.String key = ...;String value = ...;
headers.add(key, value);
Kaydol:
Kayıtlar (Atom)