Latest Added Tutorials
Introduction:
Soft delete is a technique used in database management to mark records as "deleted" without physically removing them from the database. This approach is particularly useful when you want to retain data for historical or audit purposes. In a Spring Boot application using Hibernate as the JPA provider, implementing soft delete functionality can greatly enhance data management. In this article, we will explore how to truly implement soft delete in Spring Boot Hibernate using the CustomInspector class.
Implementing Soft Delete with CustomIn...Continue Reading
01-07-2022
We can integrate JWTS token for Spring REST API by using following component:
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtParser;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.impl.DefaultClaims;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.function.Function;
@Component
public class JwtUtils {
private static final Logger logger = LoggerFactory.getLogger(J...Continue Reading
In Spring 4, we can use following configuration to adjust concurrent session count:
To use concurrent session support, you’ll need to add the following to web.xml:
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
In addition, you will need to add the ConcurrentSessionFilter to your FilterChainProxy. The ConcurrentSessionFilter requires two properties, sessionRegistry, which generally points to an instance of SessionRegistryImpl, and expiredUrl, wh...Continue Reading
You need to provide your own Binding methods and then create the correct subtypes. Spring wouldn't know otherwise which of the subtypes should be instantiated for which element.
Example: Url address can be like this: /proje-basvuru/ilk-uzun-metrajli-film or /proje-basvuru/kisa-film
@ModelAttribute("project")
public Project getProject(final HttpServletRequest request){
return createProject(getProjeBasvuruUrl(request.getRequestURI()));
}
private Project createProject(String projectType) {
if (projectType.equals("ilk-uzun-metrajli-film"))
r...Continue Reading
HsqlDb Connection
1. Download hsqldb.zip file from here
2. Extract zip file
3. Open bin folder in the hsqldb folder
4. Edit runServer.bat file as follows:
cd ..\data
@java -classpath ../lib/hsqldb.jar org.hsqldb.server.Server -database.0 mem:sample -dbname.0 sample
5. Save and run runServer.bat file
6. After running this file you should see the command prompt as follows:
Spring applicationContext-test.xml File
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"...Continue Reading
28-05-2016
Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. Aspects enable the modularization of concerns such as transaction management that cut across multiple types and objects. (Such concerns are often termed crosscutting concerns in AOP literature.)
Lets start how to configure load time weaving in Spring framework.
applicationContext.xml Configuration
<bean id=...Continue Reading
21-02-2016
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/applicationContext.xml",
"classpath:/mvc-dispatcher-servlet.xml",
"classpath:/spring-security.xml"})
@WebAppConfiguration
public class UserControllerTest {
@Autowired
private UserService userService;
@Autowired
WebApplicationContext wac;
private MockMvc mockMvc;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).apply(springSecurity()).bui...Continue Reading
11-02-2016
Maven Dependencies
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.4.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>4.0.0.RELEASE</v...Continue Reading
08-02-2016
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/applicationContext.xml", "classpath:/mvc-dispatcher-servlet.xml",
"classpath:/spring-security.xml"})
@WebAppConfiguration
public class GumrukServiceUtilTest {
@Autowired
WebApplicationContext wac;
@Autowired
private UserService userService;
private MockMvc mockMvc;
@Before
public void setup(){
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();...Continue Reading
Maven Dependencies
<properties>
<spring.test>4.1.4.RELEASE</spring.test>
<junit.version>4.12</junit.version>
<hamcrest.version>1.3</hamcrest.version>
<mockito.all>2.0.2-beta</mockito.all>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.test}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactI...Continue Reading
Spring Configuration
<http auto-config="false" use-expressions="true"
entry-point-ref="loginUrlAuthenticationEntryPoint">
<intercept-url pattern="/index" access="permitAll"/>
<intercept-url pattern="/kayit" access="permitAll"/>
<intercept-url pattern="/sifre-hatirlatma" access="permitAll"/>
<intercept-url pattern="/checkUser" access="permitAll"/>
<intercept-url pattern="favicon.ico" access="permitAll"/>
<intercept-url pattern="/kullanici/**" access="hasAnyAuthority('ROLE_ADMIN','ROLE_OFFICER','ROLE_CLIE...Continue Reading
Create Password
After downloaded Jasypt CLI Tools, execute following code by using encrypt.sh for linux based OS, or encrypt.bat file for Windows located in bin folder:
encrypt.bat input="secret" password=encryptorpassword algorithm=PBEWithMD5AndTripleDES
Output looks like this: AdK2HjMDfxTABg9ZP3kXSWsKo3t4rSn7
Note: Whenever run above command in command prompt, you will get different password each time because PBEWithMD5AndTripleDES algorithm and many other algorithms use random salt generator. For more information please click
Add Maven Depe...Continue Reading
@InitBinder annotations is used to resolve type mismatch and bind exceptions occured in a form application.
In this tutorial, we will try to explain how to use @InitBinder annotation to catch submitted collections in a form application.
Lets create a JSP file as follows:
<form:form commandName="belge" action="/kullanici/belge/kaydet">
<form:select multiple="true" path="belgeSatirlar[0].gumrukKodlari">
<c:forEach items="${gumrukler}" var="gumruk">
<option value="${gumruk.kod}">${gumruk.aciklama}</option>...Continue Reading
<intercept-url pattern="/admin/home/addUser" access="hasRole('ROLE_ADMIN')"/>
<intercept-url pattern="/admin/home/**" access="hasAnyAuthority('ROLE_ADMIN','ROLE_NORMAL')"/>
admin/home/addUser paths can only be accessed by ROLE_ADMIN and any other web pages located in /admin/ is accessed ROLE_ADMIN and ROLE_NORMAL. But notice that addUser page is also in /admin/ directory. By writing addUser url before more general path, /admin/home/**, we made a kind of filter....Continue Reading
Internationalization (i18n) or localization (L10n) is used to change language of a web application for better interaction. In this article, I will try to configure Spring MVC web application to use the Internationalization concept.
Spring MVC Configuration Steps
1. mvc-dispatcher-servlet.xml file
<mvc:interceptors>
<!-- Changes the locale when a 'lang' request parameter is sent; e.g. /?lang=tr -->
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="para...Continue Reading