0

I have a simple mavenized Spring 3.1 MVC application with running in Eclipse on a Tomcat 6.0 server.

My controller is Autowiring a DAO as shown below

@Autowired
private UserDAO userDAO;

@Component
public class UserDAO extends NamedParameterJdbcDaoSupport implements UserDetailsService {....}

I have <mvc:annotation-driven /> in my spring context file. All works well. Now, I did a ctrl+c + ctrl+p (copy-paste) of UserDAO. I kept the name as CopyOfUserDAO. I changed the private class in Controller to CopyOfUserDAO. When I start tomcat, it is unable to find CopyOfUserDAO bean. I did all kinds of clean-up but it is unable to find the CopyOfUserDAO. I even created a new class from scratch and updated controller and yet it is unable to find it.

What am I doing wrong?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Jeet
  • 311
  • 1
  • 4
  • 21

3 Answers3

1

If you check name and package of new dao class and you find everything is ok then check after compiling your project package of dao or project to contain the new class. after that try clean tomcat cache. stop and start of tomcat. if you deploy war file check war file for new dao file exist and if it ok try to copy it manually to webapp folder.

jdev
  • 5,304
  • 1
  • 17
  • 20
  • I actually tested all options :( I changed the controller to use UserDAO and started the server. While the server is running, I modified CopyOfUserDAO. I see that status of my project under server (in server view) changes from synchronized->restart->synchronized. I see the class file updated, but the server doesn't restart. If I do the same with UserDAO, as soon as I change the code, within a few seconds, server restarts. This tells me that for some reason, CopyOfUserDAO is not considered a deployed component. – Jeet Nov 20 '13 at 16:31
0
@Component
public class UserDAO extends NamedParameterJdbcDaoSupport 
                  implements UserDetailsService {....}

I couldn't understant what you are doing, why you are implementing a service class from dao layer. If yoy want to create object for dao then use @Repository annotation or you are using a service means use @Service annotation

Monicka Akilan
  • 1,501
  • 5
  • 19
  • 42
  • I am at a very initial stage of building my application. Is your answer a solution to my issue? Or is it just the pattern you are referring to? Thanks! – Jeet Nov 21 '13 at 15:49
  • Its solution try @Repository annotation for your dao – Monicka Akilan Nov 22 '13 at 03:00
  • I don't think this is a solution. Please check this.... http://stackoverflow.com/questions/6827752/whats-the-difference-between-component-repository-service-annotations-in. I figured out my issue. Please see answer below. – Jeet Nov 26 '13 at 03:46
0

I figured out my issue. I forgot to add 'context:component-scan' !! I had a manual declaration of UserDAO in my application context and hence it was discovered/instantiated.

So, in addition to

<mvc:annotation-driven />

we need to add

<context:component-scan base-package="package where classes are declared.">

I spent cycles chasing maven issue. This issue is not at all related to Maven.

Jeet
  • 311
  • 1
  • 4
  • 21