Announcement Announcement Module
No announcement yet.
Autowire dependencies not found Unit Test Maven Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowire dependencies not found Unit Test Maven

    Sorry about the cryptic title but I wanted to capture the essentials of the issue. I am running into a wall trying to configure a Junit test with

    public class UserServiceIntegrationTest {

    In the past I have created my own bootstrapper classes using ClasspathXmlContext and written code in unit test base classes to set up dependencies correctly, but I wanted to try this new Annotation based approach. At any rate I wrote a unit test:
    public class UserServiceIntegrationTest {

    private UserService userService;

    public void testInitialization() {

    Now the class to be insantiated has an entry in it like so:

    public class UserService extends ServiceBase {
    private static Logger logger = Logger.getLogger(UserService.class);

    @Resource(name = "mongoTemplate")
    private MongoTemplate mongoTemplate;

    At any rate when I go to run the Unit test in eclipse, spring throws an error indicating that it cannot find the class for the MongoTemplate dependency.
    Caused by: java.lang.ClassNotFoundException: plate

    I am using maven to resolve dependencies but apparently the SpringJUnit4ClassRunner doesn't seem to be aware of this dependency resolution.

    Any thoughts on how to get the Junit tests to use the Maven dependencies?

    I love answering my own questions, stupid user me

    <!-- Offers convenience methods and automatic mapping between MongoDB
    JSON documents and your domain classes. -->
    <bean id="mongoTemplate" class=" ongoTemplate">
    <constructor-arg ref="mongo" />
    <constructor-arg value="doitnext" />

    It would help if the class declared in the IntegrationTest-context.xml was correct.
    Last edited by steowens; Sep 4th, 2011, 11:54 AM.