【问题标题】:NetBeans: add Spring IOC to maven based Swing Application Framework projectNetBeans:将 Spring IOC 添加到基于 maven 的 Swing 应用程序框架项目
【发布时间】:2010-02-08 15:58:06
【问题描述】:

我想将 spring IOC 添加到基于 maven 的 Swing 应用程序框架项目。于是我在 pom.xml 中添加了依赖:

<!-- 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()中初始化ApplicationContext:

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

    launch(DesktopApplication1.class, args);
}

但我无法构建项目,因为 IDE 根本看不到 spring 库。我试图删除&lt;scope&gt;runtime&lt;/scope&gt;这一行,但它并没有解决问题(IDE看不到注释,例如@Autowire)。

如何将 Spring IOC 支持添加到 NetBeans Swing 应用程序框架项目(使用 maven)?

【问题讨论】:

    标签: java spring netbeans


    【解决方案1】:

    确保您已在 NetBeans 中创建了一个新的 Maven 项目,而不仅仅是一个“Java 桌面项目”(这些项目无法识别 pom.xml)。当向导要求您选择原型时,请确保选择“Swing 应用程序框架项目”maven 原型。
    检查一下,您的项目图标在左上角是否有一个小“M”(表示它是一个 Maven 项目)

    【讨论】:

    • 我需要在 pom.xml 中使用&lt;scope&gt;runtime&lt;/scope&gt; 吗?我读了static.springsource.org/spring/docs/3.0.x/…,但它不适用于范围......
    • 您应该使用范围编译,因为您使用的是@AutoWired 注释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 2011-02-12
    • 2019-04-05
    • 1970-01-01
    相关资源
    最近更新 更多