IntelliJ Java IDE
The moose likes Spring and the fly likes Exception during application startup Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply 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: 8457

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, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8457

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: 8457

Here is my applicationContext.xml snippet:



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

Joined: Nov 24, 2005
Posts: 14361

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


[SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Help Japan. Make a donation.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8457

Here it is.

Christophe Verré
Marshal

Joined: Nov 24, 2005
Posts: 14361

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

Joined: Sep 26, 2006
Posts: 8457

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: 8457

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: 8457

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

Joined: Nov 24, 2005
Posts: 14361

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: 8457



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: 8457

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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

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: 8457

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



Christophe Verré
Marshal

Joined: Nov 24, 2005
Posts: 14361

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

Joined: Sep 26, 2006
Posts: 8457

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

Joined: Sep 26, 2006
Posts: 8457

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

Joined: Nov 24, 2005
Posts: 14361

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: 8457

Here is my web.xml:

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 8457

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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

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: 8457

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é
Marshal

Joined: Nov 24, 2005
Posts: 14361

Yes.
 
 
subject: Exception during application startup
 
Threads others viewed
Getting exception of org.dom4j.DocumentException : feature read only while deploying war file in tom
Error while starting the tomcat.
my package doesnt contain ObjectFactory.class or jaxb.index
Web application
AspectJ LTW using Spring
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com