Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

there is no way to use spring annotations “service ” autowired" in a non web project

 
alper kopuz
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple maven project (not a maven web project) and I want to use spring annotations in my code. I have successfully used spring-context and spring-core in my pom.xml and I defiened applicationContext.xml with . But I can not find or use org.springframework.stereotype (Service, Autowired Annotations) in my code. It is not possible to use such kind of Spring basic annotations if my project is not a web based project ?

Cheers

"Does not work" means it gives compile error . this is pom.xml 's dependency :

     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
and this is my import which does not work

import org.springframework.stereotype
 
s ravi chandran
Ranch Hand
Posts: 473
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should work as per my understanding. Will get back after trying this out. I do remember using context scan in my project.
As far as I remember we should have two config nodes for this. One for enabling autowire and other for context scanning annotations
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!