Change beans.xml filename in Spring MVC

Spring Framework logo

If you start using Spring MVC to develop Web Applications and you declare the DispatcherServlet in web.xml, it’s a little bit annoying to rename the Spring beans file to xxxx-servlet.xml, for example, if you declare DispatcherServlet like this:

Your beans.xml file has to be renamed to springservlet-servlet.xml to let DispatcherServlet find the configuration file. But, we can change this behavior by specifying to DispatcherServlet the name of our Spring Beans file in the next way:

Continue reading

Set/change sheet name in Excel (Apache POI)

I’ve been working on a project involving a lot of Excel files processing using Apache POI library. I was coding a method to generate an Excel report with various sheets, and to stylish a little bit i wanted to set sheet names, but looking for a method like sheet.setName(), i couldn’t find anything. Looking in the documentation i couldn’t find anything, but navigating a little bit i found this post on stackoverflow:

Basically, you use the Workbook object instead Sheet object, based on sheet index beginning from zero:



Connection pool in JBoss 7.1/Wildfly 8.2

When deploying production applications, the best way to handle database connections is through a connection pool. Actually, most of JEE containers can manage connection pools, thus, you only request a connection from your application to the server and server is in charge of manage active connections and serve connections when needed. JBoss lets you configure a datasource and then configure a connection pool. The steps are the next:

  1. Register JDBC library as a module
  2. Create a new database driver based on JDBC module
  3. Create a datasource

1. Register JDBC library as a module

I’m using PostgreSQL 9.3 so i have postgresql-9.3-1102-jdbc41.jar . Navigate to JBoss directory. Inside you will find a folder named modules. Here, you will see various modules already present in JBoss or Widlfly. In Wildfly is a little bit different because inside modules folder, you only will find a folder named system. The idea is to separate system modules from your modules. You will have to create your own folders inside it.

Continue reading

Set Conversation timeout on CDI Beans

Conversation scope is a nice feature when you want to save values over request on different pages as long as you still interact with the same bean. Basically is a session scope where you have to start the conversation explicitly with a default timeout (unless you finish the conversation manually).

Default CDI Conversation scope timeout is 30 minutes. This means that, if you stop interacting with the GUI and there’s no requests to server side components, server saves conversation data during 30 minutes until it destroys it. That’s a lot of time.

You can define conversation timeout by using setTimeout() method of Conversation object by defining time in milliseconds. In the next example the timeout is set to 20 seconds. You can test timeout by pressing the button a couple of times to increase counter, then wait 20 seconds without doing anything and then pressing again a couple of times.

Continue reading