[Spring] Simple Example with @Value and annotation driven configuration (no xml)

This is an example of a simple maven Spring application run as a standalone application which demonstrates the use of properties files and annotation based configuration. 1. The Configuration Bean. Here are 2 important things: You need to provide basePackages to the package where your applicaiton resides. In particular, where you MainClass resides. You need…

Thymeleaf: #strings utility method for string objects


[SOLVED] Spring Security allow webjars through

So if you implemented Spring Security in your project, you might have problems with webjars not being allowed through. You need to set this configuration in your WebSecurityConfiguration:   [code language=”java”] @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/webjars/**").permitAll(); http.authorizeRequests().anyRequest().authenticated(); http.formLogin() .loginPage("/login") .failureUrl("/login?error") .usernameParameter("email") .permitAll() .and() .logout() .logoutUrl("/logout") .deleteCookies("remember-me") .logoutSuccessUrl("/") .permitAll() .and() .rememberMe(); }…

[REFERENCE] Spring Data JPA useful keywords for methods names

Keyword Sample JPQL snippet And findByLastnameAndFirstname … where x.lastname = ?1 and x.firstname = ?2 Or findByLastnameOrFirstname … where x.lastname = ?1 or x.firstname = ?2 Between findByStartDateBetween … where x.startDate between 1? and ?2 LessThan findByAgeLessThan … where x.age < ?1 GreaterThan findByAgeGreaterThan … where x.age > ?1 After findByStartDateAfter … where x.startDate >…

[STARTER] Spring Boot + Thymeleaf run on Tomcat 8

1. Application class [code language=”java”] package demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Demo3Application { public static void main(String[] args) { SpringApplication.run(Demo3Application.class, args); } } [/code] 2. ServletInitializer [code language=”java”] package demo; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Demo3Application.class); } } [/code] 3….

[STARTER] Spring + AOP (Aspect Oriented Programming)

1. The Performance interface

2. The actual Aspect

3. RockPerfomance

4. Beans Configuration

5. Main class

6. pom.xml

7. Layout

[Starter] Spring Runtime autowiring (Implicit bean discovery) – non boot

Here is a starter for a Spring 4 + Maven application that makes use of implicit bean discovery and loads some data from a properties file: 1. The bean. Make sure to: create a default constructor. add the @Component annotation denoting that it will be a bean [code language=”java”] package com.vvirlan.spring.examples; import org.springframework.stereotype.Component; @Component public…