spring

A Scala Spring Framework dependency injection example

Curious about how well Scala would play with the Spring Framework, I created a small Scala/Spring dependency injection example project, which I'm sharing here.

The short answer is that Scala worked just fine with Spring, but it also showed me that I still have plenty to learn about inheritance in Scala.

My Spring applicationContext.xml file

I copied a Spring applicationContext.xml file from another project, then whittled it down to these bare essentials:

A Spring MySQL BasicDataSource connection example

Spring MySQL FAQ: Can you share a Java Spring MySQL example, showing how to create a Spring Framework application context file so a Java standalone application can connect to a MySQL database?

Sure, here's a Java/Spring MySQL example, specifically showing a Spring application context file that sets up a BasicDataSource (connection) to let your Java application connect to a MySQL database.

The Spring MySQL application context file

Here's the source code for the Spring MySQL application context file (which I named applicationContext.xml):

Spring Dao - JDBC SELECT statement examples

Spring JDBC/Dao FAQ: Can you share some Spring JDBC examples, specifically SELECT query examples using Spring Dao objects?

Sure. I've done a lot of work with Spring lately, and I love the Spring Dao approach, so this page is a collection of Spring JDBC SELECT query examples (Spring DAO examples) from a real-world Java project I've been working on. In each example I try to show each type of SQL SELECT query that I've used in that project, with a brief explanation before each SQL query.

Spring Dao/JDBC tip - a great way to test your Spring DAO code

The Spring Framework gives you a great way to test your Spring JDBC (Spring DAO) code. Just use a special Spring JDBC class with a very long name, and you can test your Spring JDBC code against a real database.

Some people don't like this approach, but I think it's invaluable for (a) testing your SQL syntax when you first create it, and (b) making sure your SQL syntax is still valid after database changes occur.

Spring JDBC - How to retrieve the auto-generated database key after an INSERT

Spring JDBC FAQ: How do I retrieve the auto-generated database key for a serial field (also known as an auto_increment field in MySQL) after I perform a SQL INSERT using Spring JDBC?

How to load multiple Spring application context files in a standalone Java application

If you ever need to load multiple Spring application context configuration files in a standalone Java application, here's some sample code that shows how to load them. In the following Java source code I load three Spring context/configuration files named dao1Context.xml, dao2Context.xml, and dao3Context.xml:

How to load a Spring application context file from a standalone Java application

Here's the source code for a standalone Java application where I load a Spring application context file with the ClassPathXmlApplicationContext method. In other blogs I've shown how to load the application context for web applications, but I also wanted to show how to do this for a standalone program.

Here's a source code for my Java program that loads a Spring application context file from the typical main method:

Fixing a Spring "unsatisfied dependency" error message

Wow, today I thought I was doing some good code cleanup, and in my nice, working application, I merged a couple of Spring application context files into one single application context file, and got this horrible-looking Spring "unsatisfied dependency" error message when trying to run my suite of unit tests:

How to load multiple Spring application context files for a web application

Here's an example web.xml configuration file where I show how to configure the Spring Framework to properly load for a Java web application. I'm intentionally trying to keep this Spring example simple, so my web.xml file has almost the bare minimum configuration.

I show how to load the Spring ContextLoaderListener class with the listener-class tag, and also show how to load multiple Spring application context files using the context-param, param-name, and param-value XML tags.

Spring application context example - using Spring in a standalone Java application

Spring application context FAQ: Can you provide an example of using a Spring application context file in a standalone Java application?

Syndicate content