File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Exception during application startup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Exception during application startup" Watch "Exception during application startup" New topic
Author

Exception during application startup

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

Here is my applicationContext.xml snippet:



Here IAdminDAO is my DAO interface and AdminDAOImple is the implementation class.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Can you show AdminDAOImpl.java ? It looks like you need to set a dataSource or a jdbcTemplate in that bean.


[My Blog]
All roads lead to JavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Here it is.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You have to set the dataSource of the JdbcDaoSupport:
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

Do I still miss anything in my applicationContext.xml declaration?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Sep 26, 2006
Posts: 9351
    
    2



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

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

I changed them accordingly as below but still there seems to be the exception:



Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

How do you get the AdminServiceImpl bean ?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

I instantiate it myself in the jsp currently.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

How to get the AdminServiceImpl wired in the applicationContext.xml?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

Here is my web.xml:

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Sep 26, 2006
Posts: 9351
    
    2

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

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception during application startup