最近我遇到了这个问题:分配运营商链理解.
在回答这个问题,我开始怀疑我自己的加法赋值运算符的行为的理解+=或任何其他operator=(&=,*=,/=等).
我的问题是,a下面的表达式中的变量何时更新到位,以便在评估期间其更改的值反映在表达式的其他位置,它背后的逻辑是什么?请看下面两个表达式:
表达1
a = 1
b = (a += (a += a))
//b = 3 is the result, but if a were updated in place then it should've been 4
Run Code Online (Sandbox Code Playgroud)
表达2
a = 1
b = (a += a) + (a += a)
//b = 6 is the result, but if a is not updated in place then it should've been 4
Run Code Online (Sandbox Code Playgroud)
在第一个表达式中,当(a …
注意:我在 Spring boot 存储库上提出了一个问题。这是链接
https://github.com/spring-projects/spring-boot/issues/9048
我正在尝试在我的实体中插入一些行,以便使用 H2 数据库在开发人员计算机上进行测试。我正在用data.sql这个。
它工作正常,创建实体,然后data.sql运行以将数据插入实体生成的表中。
但是,我需要创建一些没有实体类的其他表,因此我正在使用schema.sql这些表。问题是,一旦我添加schema.sql到项目中,Spring Boot 就会data.sql在创建实体之前运行,这会导致Table not found异常。
如何同时
data.sql使用和 实体类?schema.sql
这是该项目的示例代码。
功能性 Maven 项目的 Git 链接可重现该问题。
https://github.com/ConsciousObserver/SpringBootSchemaSqlIssue.git
package com.test;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestDataSqlApplication {
public static void main(String[] args) {
SpringApplication.run(TestDataSqlApplication.class, args);
}
}
@Entity
@Table(name="USER_DETAILS")
class UserDetails {
@Id
@GeneratedValue
private Long id;
private String name; …Run Code Online (Sandbox Code Playgroud) 我面临着架构假设的问题。小背景:我正在编写一个游戏服务器,它可以为指定的玩家创建房间,并且在该房间(websocket)内,服务器正在侦听任何事件(例如玩家丢失、互联网断开等)。整体性将是可扩展的,因此将在一些 LB 监督下部署多个 Tomcat 节点。目前我已经弄清楚了这个过程(还记得关于 tomcat 集群):
客户端通过 REST API 登录到 GameServer,会话保存在所有节点之间共享的 RedisDB 中。服务器返回 HTTP 200。
客户已登录系统,他决定搜索游戏。调用“/search/game”端点。
2.1. 系统处理用户请求并将播放器添加到 RedisDB 的临时队列(下一个或同一实例现在不确定),并向客户端返回 HTTP 200。
一个特定节点上的调度程序每 10-20 秒运行一次。并查看 RedisDB 是否有任何记录,如果是真的,那么服务器会一直将玩家并列并为他们创建游戏室,直到 RedisDB 为空或有奇怪的玩家。
我不确定如何在 websocket 中并置特定的播放器并使其对其他节点可见。我用谷歌搜索了一段时间,发现了一个类似的例子
堆栈:tomcat 集群中的 Spring Websocket
用户 Thanh Nguyen Van 提到了通过多个 tomcat 实例处理 websockets 流量的两种方法,所以我决定使用 Apache ActiveMq JMS 和 Apache Camel 作为处理 websockets 流量的解决方案。
我已经在沙盒应用程序上成功实现了它,其中 3 个不同的用户可以登录系统并相互发送私人消息。整体搭配来实现ActiveMq,Camel,STOMP,SockJS和Spring Boot。很公平……但这是我坚持的部分。我觉得我已经得到了我需要的所有积木,但我不能把它们放在一起。
首先,我不确定给定的过程是否适合提出的问题。我正在考虑points 2 and 3,而不是调用REST endpoint和添加玩家RedisDB …
我正在使用受 Spring Security SSO 登录(使用 Cloudfoundry UAA)保护的 Spring 微服务。
部署在云上的微服务可通过HTTPSURL访问。由于 HTTPS URL 属于 ELB(负载均衡器/Web 服务器),因此来自 ELB 对微服务的实际请求会发生HTTP。因此,Spring 在将用户重定向到登录页面时会在302 Location标头中生成 HTTP URL 而不是 HTTPS URL 。
以下是流程
Browser
->(https://mymicroservice.com) Unauthenticated request (Load balancer)
->(http://internal_lan_ip:someport) Microservice
-> 302 Location http://mymicroservice.com/login
-> Browser http://mymicroservice.com/login (failed)
In short it goes from HTTPS -> HTTP -> 302 HTTP (failed as ELB doesn't serve on HTTP)
Run Code Online (Sandbox Code Playgroud)
以下是我尝试过的
x-forwarded-proto
由于负载平衡器也没有x-forwarded-proto正确填充到HTTPS,而是给了我HTTP,我不能使用 Spring 对它的支持。
需要通道 HTTPS
它也不起作用,因为它会导致来自 …
我也尝试使用DirectX 桌面复制 API。
\n\n我尝试运行示例
\n\nhttp://www.codeproject.com/Tips/1116253/Desktop-Screen-Capture-on-Windows-via-Windows-Desk
\n\n并从
\n\nhttps://code.msdn.microsoft.com/windowsdesktop/Desktop-Duplication-Sample-da4c696a
\n\n这两个都是使用 DXGI 进行屏幕捕获的示例。
\n\n我的机器上NVIDIA GeForce GTX 1060有。Windows 10 Pro它有Intel\xe2\x84\xa2 Core i7-6700HQ处理器。
NVIDIA Control Panel > 3D Settings当选择为时,这些示例工作得非常好Auto select processor。
但是,如果我手动将设置设置为NVIDIA Graphics Card样本将停止工作。
以下行发生错误。
\n\n//IDXGIOutput1* DxgiOutput1\nhr = DxgiOutput1->DuplicateOutput(m_Device, &m_DeskDupl);\nRun Code Online (Sandbox Code Playgroud)\n\n错误hr(HRESULT)是DXGI_ERROR_UNSUPPORTED 0x887A0004
我是 DirectX 新手,我不知道这里的问题,NVIDIA 不支持 DirectX 桌面复制吗?
\n\n如果是这种情况,那么有没有办法在程序启动时选择特定处理器,以便程序可以使用任何设置运行?
\n\n#编辑
\n\n我正在尝试将本机查询转换为 JPQL。在本机查询中, from 子句中有一个子查询。像下面这样
select * from table1 join (select * from table2) on ...
Run Code Online (Sandbox Code Playgroud)
因为我没能写JPQL一样的,因为它不允许在子查询from clause,我创建了标注有休眠的另一实体类@SubSelect("select * from table2")。现在我可以from在上述查询的子句中使用这个实体来代替子查询。
但是有两件事不太正确
@SubSelect 不使用 JPQL 查询,所以我必须放置本机查询。@SubSelect 是一个休眠特定的注释,我试图避免休眠特定的包。有@SubSelect等价的JPQL吗?
任何提示表示赞赏。
以下是上下文路径的 Spring Boot 配置
server.servlet.context-path=/rootContext
Run Code Online (Sandbox Code Playgroud)
是否可以为其创建多个别名,以便在/rootContext_2和上提供相同的应用程序rootContext_3?
我本质上想为不同的别名配置不同的安全机制。
在关于ip4地址类的教程中:http:
//www.tutorialspoint.com/ipv4/ipv4_address_classes.htm
B类有16384个(2**14)网络地址和65534个(2**16-2)主机地址.
C类提供2097152个(2**21)网络地址和254个(2**8-2)主机地址.

在关于ip4地址类的教程中:
http://www.vlsm-calc.net/ipclasses.php
B类具有163842(2**14-2)网络地址和65534个(2**16-2)主机地址.
C类提供20971520个(2**21-2)网络地址和254个(2**8-2)主机地址.
它们都是A类,网络数量是126 (2**7 – 2).
B类和C类的网络数量是否正确?
对于B类,网络的数量是 (2**14-2) 或(2**14)?
对于C类,网络的数量是 (2**21-2) 或(2**21)?
我正在尝试使用ResourceServerConfigurerAdapter(使用 Oauth2 client_credentials)访问受 Spring Security 保护的 Web 服务
以下是安全配置
//Micoservice 1
@Configuration
@EnableResourceServer
class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
@Autowired
private Environment env;
@Autowired
private DummyUserFilter dummyUserFilter;
@Override
public void configure(HttpSecurity http) throws Exception {
http.addFilterAfter(dummyUserFilter, LogoutFilter.class)
.formLogin().disable()
.httpBasic().disable()
.csrf().disable()
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/js/**", "/webjars/**").permitAll()
.anyRequest()
.authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
此应用程序(微服务 1)将由另一个应用程序(微服务 2)使用Oauth2RestTemplate. 以下是Oauth2RestTemplate配置。
//MicroService 2
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate() {
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
resourceDetails.setAccessTokenUri("https://<UAA>/oauth/token");
resourceDetails.setClientId("#####");
resourceDetails.setClientSecret("#####");
resourceDetails.setGrantType("client_credentials");
resourceDetails.setTokenName("access_token"); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring SseEmitter实现服务器发送事件,如此Youtube 视频中所述。
我能够启动事件流并从服务器发送的事件接收数据。
但是,我可以看到EventStream从客户端发出并到达服务器的多个类型的请求。我理解它的方式,EventSource应该发送一个HTTP请求,然后应该保持half duplex与服务器的连接,使用哪个服务器将事件发送到客户端。
为什么它会定期发送请求?是不是就像轮询而不是半双工连接?
波纹管是我正在使用的代码。
服务器代码
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter.SseEventBuilder;
@RestController
public class TestService {
private List<SseEmitter> subscriberList = Collections.synchronizedList(new ArrayList<>());
@RequestMapping("inbox")
public SseEmitter inbox() {
SseEmitter subscriber = new SseEmitter();
subscriberList.add(subscriber);
subscriber.onCompletion(() -> {
subscriberList.remove(subscriber);
System.out.println("Removed the completed event emitter");
});
System.out.println("Subscriber arrived");
return subscriber;
}
@RequestMapping("message")
public String message(@RequestParam("message") …Run Code Online (Sandbox Code Playgroud) java ×8
spring ×6
spring-boot ×4
javascript ×2
apache-camel ×1
c++ ×1
directx-11 ×1
eventsource ×1
ip ×1
jpql ×1
networking ×1