2010-02-08 30 views
1

我想将Spring IOC添加到基于Maven的Swing应用程序框架项目中。所以我加入到pom.xml的依赖关系:NetBeans:将Spring IOC添加到基于Maven的Swing应用程序框架项目

<!-- 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> 

而且在main()initializated的ApplicationContext:

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

    launch(DesktopApplication1.class, args); 
} 

但我不能建项目,因为IDE看不到春天的图书馆都没有。我试图删除<scope>runtime</scope>行,但它不能解决问题(IDE无法看到注释,例如@Autowire)。

我应该怎么做才能将NetBeans Swing应用程序框架项目(使用maven)添加到Spring IOC支持?

回答

1

确保您已经在NetBeans中创建了一个新的Maven项目,而不仅仅是一个'Java Desktop Project'(这些不能识别pom.xml)。确保在向导要求您选择原型时选择'Swing Application Framework项目'maven原型。
检查,你的项目图标必须在左上角一个小“M”(表示这是一个Maven项目)

+0

我需要在pom.xml中'运行'?我阅读http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/overview.html#d0e679,但它不适用于范围... – 2010-02-09 09:47:13

+0

您应该使用范围编译因为您正在使用@AutoWired注解。 – 2010-02-09 11:22:52

相关问题