【问题标题】:Intellij IDEA – Auto reload a web applicationIntellij IDEA – 自动重新加载 Web 应用程序
【发布时间】:2016-09-13 19:38:13
【问题描述】:

我正在使用 IntelliJ IDEA 15 和 tomcat 开发 AngularJS 和 Spring boot 应用程序,每当我对静态内容进行更改时,我总是重新启动我的应用程序以查看这些更改。

我找了一个类似的问题,我发现了这个:

Enable IntelliJ hotswap of html and javascript files

但我在任何地方都找不到Update resources 选项:

编辑:

这是我的项目结构:

这是我的 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.***.***</groupId>
    <artifactId>***_project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>***_PROJECT</name>
    <description>***Project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-social-facebook</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
        <!-- spring security dependency -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- end spring security dependency -->
         <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
         </dependency>
    </dependencies>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

</project>

【问题讨论】:

标签: angularjs intellij-idea spring-boot


【解决方案1】:

在 Spring Boot 应用程序中,如果您将 spring-boot-devtools 模块作为依赖项之一,它可以为您提供额外的功能,例如每当类路径上的文件更改时自动重启应用程序。

添加以下依赖项

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>

如果使用 Gradle

dependencies {
    compile("org.springframework.boot:spring-boot-devtools")
}

由于您使用IntelliJ 触发自动重启,您需要制作项目(Build -&gt; Make Project)(在 Windows 上为 Ctrl + F9)

欲了解更多信息,请访问here

有关在何处添加静态内容的更多信息 -> here

【讨论】:

  • 我不敢说它不起作用,在制作项目之后我必须如何运行它,我在我的情况下使用 Shift+10 但我看不到修改当我刷新我的 html 页面时,我还检查了 maven 依赖项,spring-boot-devtools 在那里
  • 你能把目录结构放在什么地方。。你的包装是什么。 .jar 还是战争?
  • 注意 Shift + F10 不是 Make Project 的默认键盘映射
  • 我的包装是 .jar 并且我在我的 spring boot 应用程序中使用了一个嵌入式 tomcat 服务器,因为 Shift + F10 用于运行项目而不是让它,所以我所做的就是我做该项目,然后我运行它
  • 如果您使用 jar,请通过docs.spring.io/spring-boot/docs/current/reference/htmlsingle/… 检查您是否正确放置了静态内容。要制作项目,您可以使用 Keymap Ctrl + F9
【解决方案2】:

我建议您使用 Spring BOOT 的开发者工具库(LiveReload 功能)。这使您能够在类路径发生更改时自动重新启动项目

文档 --> http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

【讨论】:

  • 恐怕不行,请检查我对帖子所做的修改
猜你喜欢
  • 2016-01-04
  • 1970-01-01
  • 2016-11-08
  • 2020-06-14
  • 2019-07-25
  • 2016-01-25
  • 1970-01-01
  • 2015-08-20
  • 2016-06-23
相关资源
最近更新 更多