我正在运行以下 Java 代码,用于从 NSE 证券交易所的 REST API 获取期权链数据。首先,我对主页进行 GET 操作,并使用后续请求中响应中的 cookie 来实际获取选项链数据。我根据计划的任务不断重复这两个步骤。它可以工作一两次,但之后它开始在 HTTP 响应中给出 401 未经授权的错误。我在两个请求标头中设置浏览器名称。任何帮助深表感谢。
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.io.InputStream;
public class PollNSEIndia {
public static void main(String args[]) throws Exception {
while (true) {
HttpURLConnection baseUrlConnection = (HttpURLConnection) new URL("https://www.nseindia.com/").openConnection();
baseUrlConnection.setRequestProperty("Connection", "keep-alive");
baseUrlConnection.setRequestProperty("Cache-Control", "max-age=0");
baseUrlConnection.setRequestProperty("Upgrade-Insecure-Requests", "1");
baseUrlConnection.setRequestProperty(
"User-Agent",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"
+ " Chrome/89.0.4389.114 Safari/537.36");
baseUrlConnection.setRequestProperty(
"Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
baseUrlConnection.setRequestProperty("Accept-Language", "en-US,en;q=0.9");
List<String> cookies = baseUrlConnection.getHeaderFields().get("Set-Cookie");
URL url = new URL("https://www.nseindia.com/api/option-chain-indices?symbol=MIDCPNIFTY");
HttpURLConnection …Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中利用 Spring Boot 3.x 中的 Observability API 进行跟踪和指标,但我对如何获取正确的可跟踪性和指标详细信息的必要设置感到困惑。
我创建了一个示例 Spring Boot 应用程序用于测试。
我在pom.xml中添加了这些依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-datadog</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
应用程序.yml:
spring:
application:
name: datadog-sample
server:
port: 8090
management:
metrics:
distribution:
percentiles-histogram:
http:
server:
requests: true
endpoint:
health:
cache:
time-to-live: 6s
show-details: always
metrics:
enabled: true
endpoints:
web:
exposure:
include: health,info,metrics
health:
jmx:
metrics:
export:
enabled: true
step: 1m
info:
env: …Run Code Online (Sandbox Code Playgroud) 我想要一个简单的 Date 类,它具有月、年和日属性。
我希望将 Date 对象包含在 Magazine 对象中,以便我可以知道 Magazine 的发布时间。
当我尝试使用 Date 类中的 Date 对象时,如下所示 Date d1 = new Date (1,1,1); 从新日期开始的日期是删除线,表明它已被弃用。我阅读了有关替换它的新构造函数的信息,但它看起来非常混乱。我不明白如何使用 Calendar 类完成此操作。如果可能,我不想创建自己的 Date 类...请帮助我。谢谢
我也看到了有关付费版本的问题,但找不到解决方案。IDEA CE 抱怨缺少应该定义的 bean。
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'domain.service.KitchenService' in your configuration.
Run Code Online (Sandbox Code Playgroud)
但在我的控制器中,我确实有它:
@Autowired
private KitchenService service;
Run Code Online (Sandbox Code Playgroud)
我发现的大多数解决方案都不清楚,唯一明确的解决方案是用 3 个注释来注释起点类@SpringBootApplication,但没有什么区别。
怎么解决呢?
请关于某些执行器端点返回 404 的小问题。我有一个基于 Webflux 2.4.2 的网络应用程序,仅用于测试此问题,我正在使用
management.endpoints.web.exposure.include=*
Run Code Online (Sandbox Code Playgroud)
Actuator 正在工作,因为 curl 将获得 /health /metrics 和其他端点的响应。
但是,对于这些端点/auditevents /httptrace /integrationgraph /sessions,除了 http 404 之外,我什么也得不到。
[05/Feb/2021:13:00:18 +0000]“选项/auditevents HTTP/1.1”404 141 55 毫秒
这些确实是返回 404 的唯一端点,仍然不知道为什么。不想在每个端点发送一个相同问题的垃圾邮件。所有其他执行器端点都很好。
谢谢
我有一个 Spring Boot 应用程序,在src/main/resources目录中有多个.properties文件,我正在使用下面通过代码给出的类似内容:
@PropertySource(value = "classpath:properties/myfunctional.properties\xe2\x80\x9d)
目前,我能够用它来完成我的工作,因为它是一个简单的功能。
\n但问题是保留所有这些.properties文件src/main/resources并不是一个好主意,原因如下:
所以,我对此有几个问题:
\n注意:我尝试过的技术很少有Spring Boot Config、Git Secret Variable等。但我再次不确定这些技术的安全程度。
\n因此,我正在寻找一个涵盖更广泛方面的答案。
\n我是 Wildfly 应用程序服务器的新手。现在,我有一个在 Wildfly 9.x 上运行良好的应用程序,但是当我尝试在 Wildfly 13.x 上部署该项目时。它给了我下面给出的错误。
这是部署后的异常:
16:09:18,173 WARN [org.jboss.modules.define] (MSC service thread 1-3) Failed to define class com.ver.dataextraction.security.services.helper.LoginHelper in Module "deployment.DataExtraction.war" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link com/ver/dataextraction/security/services/helper/LoginHelper (Module "deployment.DataExtraction.war" from Service Module Loader): org/springframework/security/authentication/encoding/MessageDigestPasswordEncoder
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:839)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:519)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:731)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
at …Run Code Online (Sandbox Code Playgroud) 我想知道这些属性之间的区别:
spring.datasource.username
spring.datasource.data-username
Run Code Online (Sandbox Code Playgroud)
同样关于:
spring.datasource.password
spring.datasource.data-password
Run Code Online (Sandbox Code Playgroud)
如何以及何时在项目中使用它?
这是我的 get API 返回员工列表。
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/get")
public List<Employee> getEmployee() {
return employeeFacade.getAllEmployee();
}
Run Code Online (Sandbox Code Playgroud)
我想Employee从ResponseEntity<String>.
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
//headers.setContentType(MediaType.APPLICATION_JSON);
Employee employee = new Employee();
HttpEntity<Employee> entity = new HttpEntity<Employee>(employee, headers);
ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class);
System.out.println("result:" + result);
Run Code Online (Sandbox Code Playgroud)
如何使这项工作?
我有一个初始时间12:00:00,我需要添加144分钟。
预期输出为15.24.00(即,初始时间增加 2.24 小时)。
我应该如何更新下面给出的当前代码?
String startTime = "13:00:00";
SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
Date date1 = null;
Date date2 = null;
try {
date1 = format.parse(startTime);
} catch (ParseException e) {
e.printStackTrace();
}
Long addition = (long) (TimeUnit.MILLISECONDS.toMinutes(date1.getTime()));
System.out.println("Difference : "+addition);
Run Code Online (Sandbox Code Playgroud) 我有一个使用 Bootstrap 4 的 Angular 12 示例项目。除了下拉列表之外,我的项目中的所有内容都正常。
这个答案对我不起作用。
我已经使用给定的 NPM 命令在我的项目中安装了 jQuery、Popper 和 Bootstrap:
npm install --save @popperjs/core
npm install --save bootstrap
npm install --save jquery
Run Code Online (Sandbox Code Playgroud)
我还从 angular.json 引用了它们:
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/@popperjs/core/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误,并且下拉按钮也出现了。但问题是,我点击后,列表并没有立即弹出。
下面给出了我从Bootstrap Dropdown 官方文档中获取的示例代码进行测试。
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我是否遗漏了一些需要添加的内容?
当我从终端运行命令时:sbt run
它像这样登录控制台:
[info] welcome to sbt 1.3.13 (Azul Systems, Inc. Java 1.8.0_362)
[info] loading global plugins from /.sbt/1.0/plugins
[info] loading settings for project from plugins.sbt ...
[info] loading project definition from /demo/project
[info] loading settings for project root from build.sbt ...
[info] __ __
[info] \ \ ____ / /____ _ __ __
[info] \ \ / __ \ / // __ `// / / /
[info] / / / /_/ // // /_/ // /_/ /
[info] …Run Code Online (Sandbox Code Playgroud) I am trying to make the equivalent of this C++ code in Java:
struct element {
int x;
int y;
};
int main()
{
element element1;
element1.x=2;
element1.y=4;
}
Run Code Online (Sandbox Code Playgroud)
What I've done so far is this:
class element {
public int x;
public int y;
}
public class Class1 {
public static void main(String[] args) {
element KK;
KK.x=1;
KK.y=2;
}
}
Run Code Online (Sandbox Code Playgroud)
I will have to create multiple element Objects and store different values in them. These are the …
java ×10
spring ×6
spring-boot ×5
angular ×1
bootstrap-4 ×1
calendar ×1
datadog ×1
date ×1
http ×1
java-time ×1
javascript ×1
jboss ×1
jersey-2.0 ×1
rest ×1
sbt ×1
scala ×1
spring-mvc ×1
wildfly ×1