Tag Archives: Spring

Spring Profile XML Configuration

If you like to load environment specific spring configuration you can do this using profile. In other words, if you want to load a set of beans that have different settings on different environment (development, testing or production) you can use profile feature instead of pointing to a different spring xml configuration at each stage.

springsource

Objective:

  • How to use profile in spring xml configuration?

Continue reading

MyBatis + Spring + Junit (The Missing Part)

We have seen in Mybatis + Spring (XML | Annotation) Mapper how to write a simple mybatis-spring app and what is actually needed to get it up and running. Here I will extend that sample code to cover more stuff that you may face in a real “coding”. We will see how to make a single select that will fetch the one and the many of a “one-to-many” relationship, who to use mybatis config file with spring (if you need it), how to test mybatis-spring code using junit and things you need to watch out!

H2 embedded database has been used to make this example easy to run. But you still can use it with other databases e.g. “MySql, Oracle,….”

mybatis-spring-junit

Objectives:

  • How to use make a single select that will fetch all one to many records?
  • How to reference mybatis config file in spring xml config file?
  • How to test using junit?

Continue reading

Spring Framework JDBC (JdbcTemplate)

Connecting to relational database (MySQL) from Java application using Spring framework JDBC JdbcTemplate class.

Objective

  • How to use Spring JDBC (JdbcTemplate) to connect database (MySql)?
  • How to:
  1. insert(object)
  2. insert(object) return id
  3. select(id) return object
  4. select(id) return single column
  5. select() return list of objects
  6. batchUpdate() more than one records!
  7. count() return # of rows!

Continue reading