我想将 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 库。我试图删除 <scope>runtime</scope>
线,但它不能解决问题(IDE看不到注释,例如@Autowire)。
如何将 Spring IOC 支持添加到 NetBeans Swing 应用程序框架项目(使用 maven)?
最佳答案
确保您在 NetBeans 中创建了一个新的 Maven 项目,而不仅仅是“Java 桌面项目”(这些项目无法识别 pom.xml)。当向导要求您选择原型(prototype)时,请确保选择“Swing 应用程序框架项目”maven 原型(prototype)。
检查一下,你的项目图标左上角是否有一个小“M”(表明它是一个 Maven 项目)
关于java - NetBeans:将 Spring IOC 添加到基于 maven 的 Swing 应用程序框架项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2222830/