- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下链接中的教程了解 Spring 的可扩展性功能。具体来说,part 6 of the tutorial使用网关应用程序来管理对其他服务器上运行的应用程序的访问。
我完全按照以下步骤操作,但是当我启动所有三个应用程序然后输入 localhost:8080/ui
在我的网络浏览器中,我得到的只是“问候”这个词,没有 id 或 hello world,也没有 css。
当我在 Firefox 中打开请求的开发人员工具时,我看到对 css 和 js 资源的 GET 请求出现 404 错误,指向像 http://localhost:8080/js/hello.js
这样的 url 而不是 指向http://localhost:8080/ui/js/hello.js
,如 the test section of the tutorial建议。 如何更改此设置以使问候语显示在浏览器中?
这是我一步一步完成的,按照教程的第六步,首先重新创建 ui
从第一部分和 resource
开始第三部分的起点:
创建 UI 示例启动应用程序
# mkdir ui
# chmod -R 777 ui
# cd ui
# curl https://start.spring.io/starter.tgz -d style=web -d style=security -d name=ui | tar -xzvf -
index.html
在
src/main/resources/static
并添加以下内容:
<!doctype html>
<html>
<head>
<title>Hello AngularJS</title>
<link href="css/angular-bootstrap.css" rel="stylesheet">
<style type="text/css">
[ng\:cloak], [ng-cloak], .ng-cloak {
display: none !important;
}
</style>
</head>
<body ng-app="hello">
<div class="container">
<h1>Greeting</h1>
<div ng-controller="home" ng-cloak class="ng-cloak">
<p>The ID is {{greeting.id}}</p>
<p>The content is {{greeting.content}}</p>
</div>
</div>
<script src="js/angular-bootstrap.js" type="text/javascript"></script>
<script src="js/hello.js"></script>
</body>
</html>
src/main/resources/application.properties
:
security.user.password=some.password
server.port: 8081
security.sessions: NEVER // The "security.sessions" setting means that Spring Security will accept cookies as authentication tokens but won’t create them unless they already exist.
pom.xml
为了使用 wro4j 下载和集成 angular 和 bootstrap 等:
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<!-- Serves *only* to filter the wro.xml so it can get an absolute
path for the project -->
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/wro</outputDirectory>
<resources>
<resource>
<directory>src/main/wro</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
<cssDestinationFolder>${project.build.directory}/generated-resources/static/css</cssDestinationFolder>
<jsDestinationFolder>${project.build.directory}/generated-resources/static/js</jsDestinationFolder>
<wroFile>${project.build.directory}/wro/wro.xml</wroFile>
<extraConfigFile>${basedir}/src/main/wro/wro.properties</extraConfigFile>
<contextFolder>${basedir}/src/main/wro</contextFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>angularjs</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.2.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
src/main/wro/wro.properties
(将从less编译css并缩小javascript):
preProcessors=lessCssImport
postProcessors=less4j,jsMin
src/main/wro/wro.xml
(声明一个引用 css、js 和 main.less 的单组 angular-bootstrap):
<groups xmlns="http://www.isdc.ro/wro">
<group name="angular-bootstrap">
<css>webjar:bootstrap/3.2.0/less/bootstrap.less</css>
<css>file:${project.basedir}/src/main/wro/main.less</css>
<js>webjar:jquery/2.1.1/jquery.min.js</js>
<js>webjar:angularjs/1.3.8/angular.min.js</js>
</group>
</groups>
src/main/wro/main.less
暂时将其留空。
main.less
可用于自定义引导默认值。
src/main/resources/static/js/hello.js
并添加以下内容:
angular.module('hello', [])
.controller('home', function($scope, $http) {
$http.get('/resource/').success(function(data) {
$scope.greeting = data;
})
});
com.example.UiApplication.java
到:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@SpringBootApplication
@EnableRedisHttpSession
public class UiApplication {
public static void main(String[] args) {
SpringApplication.run(UiApplication.class, args);
}
}
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
# cd /home/username/someworkspace
# mkdir resource
# chmod -R 777 resource
# cd resource
# curl https://start.spring.io/starter.tgz -d style=web -d name=resource -d language=java | tar -xzvf -
pom.xml
在
resource
应用程序:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
com.example.ResourceApplication.java
到以下:
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
@EnableRedisHttpSession
public class ResourceApplication {
@RequestMapping("/resource")
public Map<String,Object> home() {
Map<String,Object> model = new HashMap<String,Object>();
model.put("id", UUID.randomUUID().toString());
model.put("content", "Hello World");
return model;
}
public static void main(String[] args) {
SpringApplication.run(ResourceApplication.class, args);
}
}
src/main/resources/application.properties
:
server.port: 9000
security.sessions: NEVER
# cd /home/username/someworkspace
# mkdir gateway
# chmod -R 777 gateway
# cd gateway
# curl https://cloud-start.spring.io/starter.tgz -d style=web -d style=security -d style=cloud-zuul -d name=gateway -d style=redis | tar -xzvf -
GatewayApplication.java
到:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
@SpringBootApplication
@EnableRedisHttpSession
@EnableZuulProxy
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
src/main/resources/application.properties
到:
zuul.routes.ui.url: http://localhost:8081
zuul.routes.resource.url: http://localhost:9000
security.user.password: password
security.sessions: ALWAYS
# cd /home/username/someworkspace/ui
# mvn spring-boot:run
# cd /home/username/someworkspace/resource
# mvn spring-boot:run
# cd /home/username/someworkspace/gateway
# mvn spring-boot: run
localhost:8080/ui
仅显示单词“Greeting”。 ,并且没有 id 也没有内容。此外,firefox 开发人员工具会显示
http://localhost:8080/js/hello.js
等资源的 404 错误。其中
应该改为
http://localhost:8080/ui/js/hello.js
localhost:8081
在浏览器中,我得到 css 样式的“问候”,后跟“ID 是”和“内容是”,但没有来自资源服务器的动态内容。
localhost:8081
的 Firefox 开发者工具请求为
http://localhost:8081/resource/
提供 404 .
kill $(lsof -t -i:8080)
或 8081 或 9000,然后是
mvn spring-boot:run
最佳答案
看起来像您的 html 页面中的问题。您应该确保链接是正确的。 Zuul 本质上所做的是将 url 从网关映射到后端。要使您的示例正常工作,您必须将 Angular 应用程序中的 url 更改为 /resource/resource
或将资源应用程序中的 Controller 更改为 /
.还要确保您的所有应用程序都具有 spring-boot-starter-security 作为依赖项,以允许共享 sec 上下文。或者完全禁用安全性以首先调试您的问题。
关于java - 为什么 spring boot angularjs gateway 应用程序不能从 ui 应用程序读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34235409/
Spring Cloud Greenwich puts spring-cloud-netflix-zuul处于维护模式,所以我正在尝试从 Zuul 迁移到 Spring Cloud Gateway。
有没有办法对 AWS API Gateway 服务使用基本身份验证而不是 AWS4-HMAC-SHA256 身份验证?我需要支持仅支持使用基本身份验证的 webhook 调用的系统。 最佳答案 您只需
Rails API 通常喜欢这样的数组查询参数: example.com?colors[]=cyan&colors[]=magenta&colors[]=yellow&colors[]=black 我
Here蓝图中说,API 网关将响应 401: Unauthorized。 我写了同样的raise Exception('Unauthorized')在我的 lambda 中,并且能够从 Lambda
在 documentation我确实看到了如何使用 Hystrix 实现超时,但我只想确保没有实现默认超时。 最佳答案 现在还有一个 chapter关于文档中的一般超时。可以设置全局超时和每条路由超时
我的资源/api 有一个方法 POST,它将主体代理到 Kinesis Firehose(然后代理到 ES)。同时我希望它触发一个 Lambda 函数。 我尝试添加一个额外的方法 ANY 来触发 La
Spring Cloud Gateway 真的很新 - 但它“似乎”很容易。我真的很苦恼的一个问题。我的要求是为路径添加前缀,检查头变量,根据该变量查找 URI,然后继续前进。 问题是 uri 总是下
我已经使用 Websocket 协议(protocol)创建了一个 API 网关。部署 API 后,我得到一个 WebSocket URL 和一个连接 URL。 例如 WebSocket URL:ws
我正在使用 AWS API Gateway 和 AWS Lambda 创建一个无服务器的 REST API。虽然已创建端点并与相应的 Lambda 函数链接,但下一步是添加身份验证层以通过电子邮件和密
我们开发了一个应用程序,它提供多种休息服务,并支持 Accept-Encoding header ,以通过 Content-Encoding:gzip header 值返回压缩内容。 此应用程序部署在
我正在开发 CloudFormation 模板来部署 API Gateway 资源,但在部署 (AWS::ApiGateway::Deployment) 和UsagePlan 资源方面遇到问题。这有点
我目前正在使用 AWS API Gateway 开发 API。我正在向我的客户发布一个 JSON Web token (JWT)。该 JWT 使用 secret 进行签名。我目前将 secret 存储
我下载了 .NET SDK对于 Payflow Gateway 并遵循 these instructions关于设置我的 Payflow Gateway 测试帐户,然后修改两行 DOSecureTok
我目前正在将 Amazon CloudSearch 与前端应用程序集成。由于已知的 CORS 问题,我也被迫使用 API 网关。 出现的问题是,前端 CloudSearch 库发送带有编码参数的 ur
我正在创建一个 LambdaRestApi在 CDK 中,我想同时启用 CORS 并使用 addProxy 方法添加任何代理。 我目前有以下 CDK 代码: const api = new Lam
我们可以使用 AWS API Gateway 使用双向 SSL 功能吗?我们希望在我们的实时流应用程序中使用 API Gateway 作为 kinesis 的代理。 下面是我的要求 客户端向 apig
我正在构建一个无服务器 react 应用程序,它使用 Cognito 进行登录/注销。该应用程序调用 API 网关,该网关配置为使用 Cognito 用户池作为自定义授权方。 我还构建了一个 lamb
我已经浏览了 Google Cloud API Gateway docs并搜索 the public issue tracker但一直无法以某种方式提及它。 我最接近的是this google gro
我正在尝试将使用 spring-cloud-starter-netflix-zuul 的网关迁移到 Spring Cloud Gateway,但我遇到了请求路由问题。 我浏览了以下有关为 Discov
我正在尝试设置我的 API 网关,以便它具有以下简单的方法响应: 我正在使用 CloudFormation,但总是遇到错误。我相信这很简单,但在花了几个小时阅读文档后我陷入了困境。这是我的方法资源(在
我是一名优秀的程序员,十分优秀!