Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception during application startup

 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a Spring web application running in Tomcat. When I try to bring the application up, I get the following error.



Is the CGLIB what it complains is a library?? Should that be added as a dependency?
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After a bit of self exploration, I found out that I missed something in the applicationContext.xml configuration. Later I corrected it and now this is the error that I face:


 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my applicationContext.xml snippet:



Here IAdminDAO is my DAO interface and AdminDAOImple is the implementation class.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show AdminDAOImpl.java ? It looks like you need to set a dataSource or a jdbcTemplate in that bean.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to set the dataSource of the JdbcDaoSupport:
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes, it worked. I did forget to specify the datasource property. The server startup was without any exceptions. Now I have to check how the declarative transaction would work by forcefully introducing some exceptions during insertion into the table. Will post here if I face any difficulties.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting a NullPointerException in the line below in my AdminDAOImpl.java



Looks like the getJdbcTemplate() returns me null. What could be the reason? Am I missing any configuration information??
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I still miss anything in my applicationContext.xml declaration?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to use the JdbcTemplate (or SimpleJdbcTemplate), you need to set it explicitly.


Or you can create a JdbcTemplate in your context file, and assign the DataSource to it, then wire it to your Dao.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Seems not to work, since setDataSource is final (in the JdbcDaoSupport) and cannot be overridden. I'm anyways wiring it in the applicationContext.xml as you can see it in my post above.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm posting my complete sources here.

My applicationContext.xml as below;



My service class from which I call the DAO implementation:



And finally my DAO implementation class:



So System.out.println("The GETJDBCTEMPLATE is ***************** " + getJdbcTemplate()); prints null???
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems not to work, since setDataSource is final (in the JdbcDaoSupport) and cannot be overridden.

Sorry, the jdbcTemplate is supposed to be instanciated when the DataSource is set. So the xml file is correct.
What puzzles me now is the following line :

Is this IAdminDAO instance retrieved by the Spring container ? If not, that would explain why the jdbcTemplate is not set.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed them accordingly as below but still there seems to be the exception:



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you get the AdminServiceImpl bean ?
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I instantiate it myself in the jsp currently.
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get the AdminServiceImpl wired in the applicationContext.xml?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I instantiate it myself in the jsp currently.

If it's not managed by Spring, the wiring process will not magically happen
You should get it from a servlet, not from a JSP. You can retrieve it any way you would for a classic application, via the ApplicationContext.

(It would even be better to autowire the service to the controller, so you wouldn't need that)

I hope you have everything configured properly. Your context file doesn't seem to have a correct name. It should be named [servlet-name]-servlet.xml, where [servlet-name] is the name you have given to the DispatcherServlet. Are you using a tutorial ?
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my web.xml:

 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just testing this app set up and all what I'm doing is just calling the AdminServiceImpl implementation in my index.jsp. Is there any additional configuration that I need to do to wire up the service?? I'm using Struts 1.3.10 framework.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaaah, ok You're not hiding some information So you are using the ContextLoaderListener. You can now access the context via WebApplicationContextUtils:
 
Joe Harry
Ranch Hand
Posts: 10080
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Aaaah, ok You're not hiding some information So you are using the ContextLoaderListener. You can now access the context via WebApplicationContextUtils:


The "application" is the jsp implicit object?? Am I right?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic