小编Ana*_*han的帖子

由于不允许的 MIME 类型(“text/html”)而被阻止:部署在 tomcat 9.0.30 上的 Angular 8 无法提供资产

我有一个项目,其中用户界面基于 angular 8,后端是 springboot java 服务。整个项目是一个多模块项目,其中 angular 部分是一个单独的模块,front-end builder用于将 angular 代码构建到单个可执行 jar 中。使用嵌入式 tomcat 时,应用程序运行良好。我有一个新要求,即尝试在外部 tomcat 上单独部署 angular ui 部分。但是当我将 dist 文件夹复制到 webapps 文件夹并尝试为其提供服务时,浏览器会阻止请求说:

Loading module from “http://localhost:8080/polyfills-es2015.js” was blocked because of a disallowed MIME type (“text/html”).
Run Code Online (Sandbox Code Playgroud)

浏览器截图

做了一些谷歌搜索后,我才明白发生的问题,因为角8个CLI未能在添加type属性到script的标签index.html。当我手动添加类型时,一切正常。任何人都可以帮助我理解为什么会发生这种情况,以及手动编辑以外的问题的可能解决方案。

生成index.html

<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>My Application</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <i class="fas fa-chart-area"></i>
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body style="margin: 0;">
  <app-root></app-root>
<script src="runtime-es2015.js" type="module"></script><script src="runtime-es5.js" …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot angular tomcat9 angular8

13
推荐指数
3
解决办法
2万
查看次数

Angular cli 显示错误“发生未处理的异常:没有项目支持‘测试’目标。” 运行 ng test 或 ng serve 命令时

我有一个基本的角度应用程序,它运行良好。在ng serveng test命令都工作正常。最近,作为针对不同环境构建自动化的一部分,我引入了一些配置更改以允许environment.ts根据环境加载不同的文件。对于我编辑的angular.jsonfile.After的变化,ng serveng test命令无法执行。每当执行命令时,都会抛出以下错误:

An unhandled exception occurred: No projects support the 'test' target.
See "C:\Users\account\AppData\Local\Temp\ng-BlbvgV\angular-errors.log" for further details.
Run Code Online (Sandbox Code Playgroud)

修改angular.json为:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "applicationui": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../applicationservice/src/main/resources/static",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets" …
Run Code Online (Sandbox Code Playgroud)

build angular angular-test angular8 angular-cli-v8

5
推荐指数
1
解决办法
2万
查看次数

使用Spring data Rest @RepositoryRestResource 创建rest端点时是否需要注释@EnableMongoRepositories

我正在尝试使用 Spring Boot 指南来使用@RepositoryRestResource注释创建 Spring Data Rest 端点。我观察到的是,在指南中,他们没有指定我们使用任何其他注释而不是@RepositoryRestResource. 所以我所做的是:

public class Merchant{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

@RepositoryRestResource(collectionResourceRel = "account", path = "account")
public interface MerchantRepository extends MongoRepository<Merchant, String> {

    List<Person> findByLastName(@Param("name") String name);

} …
Run Code Online (Sandbox Code Playgroud)

java spring spring-data-rest spring-data-mongodb spring-boot

2
推荐指数
1
解决办法
1万
查看次数