简体   繁体   中英

NetBeans: add Spring IOC to maven based Swing Application Framework project

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)?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM