I have following configuration
web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<servlet>
<servlet-name>minapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>minapp</servlet-name>
<url-pattern>hello.htm</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>register</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>register</servlet-name>
<url-pattern>/register/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
</web-app>
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/minapp" />
<property name="username" value="root" />
<property name="password" value="verysecret" />
</bean>
<bean id="myUserDAO" class="no.java.UserDAOImpl">
<property name="DataSource" ref="myDataSource"/>
</bean>
<bean name="/register/register.htm" class="no.java.RegistrationController" >
<property name="UserDAO" ref="myUserDAO" />
</bean>
</beans>
setter for RegistrationController
private UserDAO userDAO;
public void setUserDAO(UserDAO userDAO) {
System.out.println("dao set");
if (userDAO == null){
System.out.println("dao null");
}
this.userDAO = userDAO;
}
setter for UserDAOImpl:
private DataSource dataSource;
public void setDataSource(DataSource source){
System.out.println("data source setter called");
this.dataSource=source;
}
And neither the RegistrationController setter nor the UserDAOImpl setter are called.
I have a feeling that i might have misplaced the configuration, but due to the complexity of Spring documentation i cant get what i have done wrong.
as far as i understand the contextConfigLocation should point spring to the applicationContext.xml , and that file should do some magic in order to setup the database connection, but it does not.
I’d be very grateful for any help.
You need to add the context loader to your web.xml also, to fire up the ApplicationContext independant of the Dispatcher Servlets.