如何在 IntelliJ IDEA 中配置 Spring facet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32861600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:48:16  来源:igfitidea点击:

How to configure Spring facet in IntelliJ IDEA

springintellij-idea

提问by user3714598

I'm new to Intellij 14.0 . I was using Netbeans, but my colleagues told me to shift to intellij and so I did.

我是 Intellij 14.0 的新手。我正在使用 Netbeans,但我的同事告诉我转向 intellij,所以我做到了。

I need to run the same project that I ran on netbeans in Intellij. The project that I'm working on is made of grails and spring. When I tried to run the project using Intellij this is what I get.

我需要在 Intellij 中运行我在 netbeans 上运行的相同项目。我正在做的项目是由 grails 和 spring 组成的。当我尝试使用 Intellij 运行该项目时,这就是我得到的结果。

Spring Configuration Check Unmapped Spring configuration files found. Please configure/setup Spring facet for modules: ......... (1 file)

Spring 配置检查未映射的 Spring 配置文件已找到。请为模块配置/设置 Spring facet:…………(1 个文件)

And this is the file.

这是文件。

applicationContext.xml

应用上下文.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
        <description>Grails application factory bean</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="grailsResourceLoader" ref="grailsResourceLoader" />
    </bean>

    <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
        <description>A bean that manages Grails plugins</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="application" ref="grailsApplication" />
    </bean>

    <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
        <constructor-arg>
            <ref bean="grailsApplication" />
        </constructor-arg>
        <property name="pluginManager" ref="pluginManager" />
    </bean>

    <bean id="grailsResourceLoader" class="org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean" />

    <bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
        <property name="encoding">
            <value>utf-8</value>
        </property>
    </bean>

    <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean" />
</beans>

Honestly, I dont have any idea how to fix it. Based on my understanding it is looking for some modules but I could not fix it. I even tried this "Add framework support" . But I couldn't find spring in the list.

老实说,我不知道如何解决它。根据我的理解,它正在寻找一些模块,但我无法修复它。我什至试过这个“添加框架支持”。但是我在列表中找不到春天。

Could you help me fix this? Thanks

你能帮我解决这个问题吗?谢谢

回答by Bohuslav Burghardt

Go to File/Project Structure/Modules, click the green plus icon, select Spring from the dropdown and select your module in the next dialog.

转到File/Project Structure/Modules,单击绿色加号图标,从下拉列表中选择 Spring 并在下一个对话框中选择您的模块。

Then click the green plus in the right pane, click plus and select your Spring configuration files and classes and click OK.

然后单击右侧窗格中的绿色加号,单击加号并选择您的 Spring 配置文件和类,然后单击确定。

Also take a look at IntelliJ Helpfor Spring Facet.

另请查看Spring Facet 的IntelliJ 帮助

回答by Wallter

Just ran into this issue out of the blue today—my build was working last night, and this morning it stopped working—so I figured I'd post my solution using IntelliJIDE CE 2019.1.

今天突然遇到了这个问题——我的构建昨晚在工作,今天早上它停止工作——所以我想我会使用IntelliJIDE CE 2019.1发布我的解决方案。

Error Messages(to help people find this answer)

错误消息(帮助人们找到这个答案)

package org.springframework.transaction.annotation does not exist
package org.springframework.boot does not exist
Unknown facet type: 'Spring'
Unknown facet type: 'web'

enter image description here

在此处输入图片说明



Solution

解决方案

Step 0: Update IntelliJ

步骤 0:更新 IntelliJ

Menu: IntelliJIDE > Check for Updates (Mac OSX) 

Step 1: Clean out Maven repo and re-download dependencies to ensure that the sources are not corrupt. This will take 5+min.

第 1 步:清除 Maven 存储库并重新下载依赖项以确保源没有损坏。这将需要 5 分钟以上。

$ cd [project_directory]
$ mvn dependency:purge-local-repository

Step 2: Preform a clean install.

第 2 步:执行全新安装。

$ mvn clean install

Step 3: Update IntelliJIDE's Repository Indexes:

第 3 步:更新 IntelliJIDE 的存储库索引:

  1. Open IntelliJ Settings/Preferences
  2. Build, Execution, Deployment > Build Tools > Maven > Repositories
  3. Select repositories one by one (by clicking on the table row) and click the update button. Specifically, do it for https://repo.mave.apache.org/maven2. The download is ±700mb so it will take a while. (10+min) enter image description here
  1. 打开 IntelliJ 设置/首选项
  2. 构建、执行、部署 > 构建工具 > Maven > 存储库
  3. 一一选择存储库(通过单击表格行)并单击更新按钮。具体来说,为https://repo.mave.apache.org/maven2做这件事。下载是±700mb,所以需要一段时间。(10+分钟) 在此处输入图片说明


Related Questions

相关问题

回答by Marc

IntelliJ Ultimate 2018 - the manual way:

IntelliJ Ultimate 2018 - 手动方式:

  1. Menu File -> Project Structure
  2. Right-click on your module and choose "Add..." -> Spring
  3. Optionally click "fix" if spring is not listed as a dependency
  4. Click the + icon at the top to add your spring configuration .xml file(s)
  1. 菜单文件 -> 项目结构
  2. 右键单击您的模块并选择“添加...”-> Spring
  3. 如果 spring 未列为依赖项,可选择单击“修复”
  4. 单击顶部的 + 图标添加您的 spring 配置 .xml 文件

enter image description here

在此处输入图片说明

The automatic way:

自动方式:

  1. Click the body of the popup notification
  2. Click the "Create Default" option
  1. 单击弹出通知的正文
  2. 单击“创建默认值”选项

enter image description here

在此处输入图片说明