views:

307

answers:

1

Hello.

I want to add spring IOC to maven based Swing Application Framework project. So I added to pom.xml dependencies:

<!-- Spring IOC -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>3.0.0.RELEASE</version>
  <scope>runtime</scope>
</dependency>

<!-- log4j for Spring -->
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.15</version>
  <scope>runtime</scope>
</dependency>

And initializated ApplicationContext in main():

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.scan("com.mypackagewithbeans");
    ctx.refresh();

    launch(DesktopApplication1.class, args);
}

But I can't build project, because IDE can not see spring libraries at all. I tried to remove <scope>runtime</scope> line, but it does not fix the problem (IDE can not see annotations, for example, @Autowire).

What should I do to add the Spring IOC support to the NetBeans Swing Application Framework project (using maven)?

+1  A: 

make sure that you've created a new Maven project in NetBeans and not just a 'Java Desktop Project' (these don't recognize the pom.xml). make sure to select the 'Swing Application Framework project' maven archetype when the wizard asks you to select an archetype.
to check, does your project icon have a small 'M' at the top left corner (indicating it's a maven project)

Stefan De Boey
Do I need `<scope>runtime</scope>` in pom.xml? I read http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/overview.html#d0e679, but it does not work with scope...
Vladimir
you should use scope compile since you're using the @AutoWired annotation.
Stefan De Boey