Spring XML and beans inheritance

If you are using XML configuration in your Spring application, you should know about gorgeous feature, that spring has: bean inheritance. What does this mean ? This mean, that you can create an abstract bean with some predefined properties, and later, you will be able to make an inheritance from this bean. Here is an example Here you have DefaultDao implementation, which has three fields - persistenceManager, which is the same in every Dao class, queryBuilder for building dynamic queries, which are dynamic field, and entityClass, which is the name of Class, that will be mapped to result from database. And here we have xml context, that we use without bean inheritance. After some modification and refactoring we will receive As you can see, we reduce number of lines in context and now we are instantiating persistenceManager from one place and if we will want to change it, we will do that very quickly.

Encoding Filter Not Encoding at all ?

Recently I experienced a problem, when I had CharacterEncodingFilter filter in my web.xml, but no encoding were done at all. I started to investigate this problem and find out, that few weeks ago I added additional filters on top of my web.xml, and , as a result, my CharacterEncodingFilter was placed on second or third position.Good news for me, I added integration test with ukrainian words, and my web service returned some incorrect characters. After few minutes, I discovered, that If you want to have correct unicode data, then you need to place encoding filter at the top of all your filters. Thereafter, your filter will the first chain and you will be sure, that all other filters will work with correct unicode.

Sending emails with Java, Spring and Handlebars

Nowadays, it’s very popular to have applications, that can somehow notificate people.We’re gonna use emails to send text and html mails to someone.Whar requirements do we need? Possibility to send simple text emails Posibility to send html emails. Of course, to send emails, we need to have some template engine. We will use handlebars for that. We will use Spring. Maven as build tool Java Mail package Handlebars template engine Greenmail for “mocking” email server. Structure We need to have four subpackages, exception package for having custom exceptions, model package for storing our model, sender package for main functionality and template package for storing template service. Your pom.xml should have similar structure So, let’s create Exception package Model package We created all required models and resources for further developing, so let’s start adding core functionality Template package Have ever you ever think about sending emails with html content ? Imagine, your application sends email with some pretty organized html page. Sound great. To do such things, of course, you need to have template engine. I prefer Handlebards template engine. [gist id=”60fd72b167cb6243c74f”] if you have template in your resources/templates folder with name template1.html, then you should call handlebars.compile(“template1”); in your code....