Nov 08 2012

Learning Spring, part VI

Category: TechnicalIuliana @ 15:44

This won’t be a post  about a problem or a question, but about an observation.

When I took the spring Core course in Belgrade this June, in the Chapter about data access the jdbcTemplate instance was created like this:
Java code:

//random DAO class
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}

Xml configuration:

<bean id="dataSource" class="..." />

After that I read Spring in Action, then the Spring reference and everywhere when given an example on how to use jdbcTemplate, the instance was created and injected like that.

And I am confused. If jdbcTemplate instance is thread-safe once configured, is recommended to not create one for each use and is stateless (does not maintain any conversational state) why don’t we just create it as a singleton bean and use it as such?
Sample of my code:

//random DAO class
private JdbcTemplate jdbcTemplate;
@Autowired
@Qualifier("jdbcTemplate")
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

Xml configuration:

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
   <constructor-arg ref="dataSource" />
</bean>

Tags: ,


Nov 06 2012

Learning Spring, part V

Category: TechnicalIuliana @ 10:37

<ref local=””/> vs. <ref bean=””/>

So here is the conclusion of this post, which was debated with my friend MARIANUL also.

The only difference between the two is syntax and  behaviour at application design time, when each of them helps you , the developer, in its own way, to figure out if the references are valid or not. At run time, there is no difference: all beans are created and reside in the same application context so the references are correctly solved.

So yeah, this is it. Simple as that. So ignore all the blog posts where you are told that code does not compile because of XML parser errors and if you doubt my findings too, dare to test and draw your own conclusions. This is what I did. :)

Tags: , , ,


Nov 05 2012

Learning Spring, part IV

Category: TechnicalIuliana @ 13:05

<ref local=””/> vs. <ref bean=””/>

So, when should we use one or the other and why?

First, I’ll offer you a link to the official Spring reference documentation related to this subject.  Basically:

Specifying the target bean through the bean attribute of the tag is the most general form, and allows creation of a reference to any bean in the same container or parent container, regardless of whether it is in the same XML file. The value of the bean attribute may be the same as the id attribute of the target bean, or as one of the values in the name attribute of the target bean.

And:

Specifying the target bean through the local attribute leverages the ability of the XML parser to validate XML id references within the same file. The value of the local attribute must be the same as the id attribute of the target bean. The XML parser issues an error if no matching element is found in the same file. As such, using the local variant is the best choice (in order to know about errors as early as possible) if the target bean is in the same XML file.

Then we will play with some source code.
Continue reading “Learning Spring, part IV”

Tags:


Oct 13 2012

Learning Spring, part III

Category: TechnicalIuliana @ 18:15

I have a new hot question for you:

We have two classes AccountServiceImpl and ClientServiceImpl. Any of these classes inherits from each other, meaning one is a subclass of the other. What will happen if we define a pointcut like this:

"execution( * *..AccountServiceImpl.update(..)) 
       && execution( * *..ClientServiceImpl.update(..)) "

And here are your options:

  1. The pointcut matches any public update methods of the two classes whatever the arguments.
  2. The pointcut matches any update methods of the 2 classes whatever the arguments and the method visibility.
  3. The pointcut matches any update methods of the two classes, with one ore more arguments and whatever the method visibility.
  4. No join point is defined.
  5. Something else will happen.

Continue reading “Learning Spring, part III”

Tags: ,


Oct 10 2012

Learning Spring, part II

Category: TechnicalIuliana @ 17:02

One of the reasons I haven’t taken SCJP yet was the stupidity of the grammar in the construction of some questions and answers on the exam.(I have given examples in the past on this blog, search a little if you are curious)  Currently I am to take the Spring Core Certification exam and  and I am terrified that I will find the same kind of questions and answers in it.  And the worst part is that there are not that many mock exam samples on the internet, so I have no chance to get used to the specific style.

For example:

In Spring Framework’s declarative transaction implementation , is it sufficient to annotate the classes with the @Transactional annotation ?
Select Your Answer :

  1. No
  2. Yes
  3. No . <tx:annotation -driven/> has to be added in configuration file

You might be inclined to say that the correct answer is 3, Continue reading “Learning Spring, part II”

Tags:


Sep 15 2012

Learning Spring

Category: English posts,TechnicalIuliana @ 23:47

A few months ago the company where I am currently employed sent me to Belgrad to train me in Spring Core. The training lasted 4 days and at the end I was supposed to take the Spring Core certification exam and pass it.

I delayed that for a while, but because now I have some spare time I decided it was time for me to do this thing. So I went over the slides and the spring code samples again. But after doing some mock tests I concluded I will most likely fail the certification, because the official materials were not enough so I started reading Spring in Action. Still I noticed that in the tests there was still stuff that I hadn’t covered. So I started reading Spring Reference. And because I have some problems in retaining information just by reading it, I stared to test the recommended examples. And this is where I hit some walls.

But before telling you what is not clear for me I shall tell you what technologies I’m using for development: Maven 3.0.0, Jdk 1.7, Intellij Idea 11.1.3 and Spring 3.1.2 (I know the certification is for 3.0, but as the Spring reference manual has 840 pages, I might as well read about the new and useful stuff added in 3.1)

The first problem I had was with the compound property names. I tried using them. Idea does not recognize them and my test fails.

Continue reading “Learning Spring”

Tags: ,


Jul 17 2012

Brain overload

Category: TechnicalIuliana @ 12:32

If you are a developer and write error messages like these :

– Simple Error bla bla bla
– Small Malfunction bla bla bla

And I end up working with your code I have only this to say:

I don’t know who you are, I don’t know what you want, If you’re trying to be funny, I can tell you I don’t have a sense of humour, but what I do have are a very particular set of skills, skills that have acquired over a very long career. Skills that make me a nightmare for people like you. If you stop writing shit debug messages like these now, that will be the end of it. But if you don’t, I will look for you. I will find you and I will kill you.

Because when it comes to code, there is no such thing as a Simple ERROR, nor a Small MALFUNCTION.