小编Shu*_*ubh的帖子

一起使用 async await 和 .then

使用async/await.then().catch()一起使用是否有任何危害,例如:

async apiCall(params) {
    var results = await this.anotherCall()
      .then(results => {
        //do any results transformations
        return results;
      })
      .catch(error => {
        //handle any errors here
      });
    return results;
  }
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous node.js promise async-await

33
推荐指数
6
解决办法
3万
查看次数

使用 gitlab ci cd pipeline 时访问 Node js 应用程序中的环境变量

我正在使用 gitlab ci cd 管道将我的应用程序部署到 ubuntu 服务器。我有不同的 .env 文件用于本地和开发环境,并且它不是 git repo 的一部分(包含在 gitignore 中)如何在部署到 ubuntu 服务器时在我的应用程序中获取环境变量

我的 gitlab-ci.yml

stages:
     - deploy
cache:
  paths:
    - node_modules/
deploy:
    stage: deploy
    script:
      - npm install
      - sudo pm2 delete lknodeapi || true
      - sudo pm2 start server.js --name lknodeapi
  
Run Code Online (Sandbox Code Playgroud)

continuous-integration node.js gitlab pm2

9
推荐指数
1
解决办法
8987
查看次数

合并bean定义的后处理失败;嵌套异常是 java.lang.IllegalStateException

这是我的 OffersDao 课程

package com.spring.dao;

import java.sql.*;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class OffersDao {


private NamedParameterJdbcTemplate jdbc;

    @Autowired
    public void setDataSource(DataSource jdbc) {
        this.jdbc=new NamedParameterJdbcTemplate(jdbc);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我没有自动装配下面的部分时,我的应用程序工作正常,否则它会给我上述错误

这是我的 spring 上下文 xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">


    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com.spring.dao"></context:component-scan>

    <jee:jndi-lookup jndi-name="jdbc/TestDB" id="dataSource"
        expected-type="javax.sql.DataSource">
    </jee:jndi-lookup>


</beans>
Run Code Online (Sandbox Code Playgroud)

如果有人能告诉我为什么会这样。而且它是一个 Maven 项目。

java spring

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

nodejs (libuv) 事件循环是否在一个阶段(队列)中执行所有回调,然后再进入下一阶段或以循环方式运行?

我正在研究 Node.js 中 libuv 提供的事件循环。我看到了Deepal Jayasekara 的以下博客,还在 YouTube 上看到了 Bert Belder 和 Daniel Khan 的解释。

有一点我不清楚 - 根据我的理解,事件循环在进入另一阶段之前处理一个阶段的所有项目。因此,如果是这种情况,如果 setTimeout 阶段不断添加回调,我应该能够阻止事件循环。

然而,当我尝试复制这一点时,它并没有发生。以下是代码:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
  console.log("Response sent");
  res.end();
}).listen(8081);


setInterval(() => {
  console.log("Entering for loop");
// Long running loop that allows more callbacks to get added to the setTimeout phase before this callback's processing completes
 for (let i = 0; i < 7777777777; i++); 
 console.log("Exiting for loop");
}, 0); …
Run Code Online (Sandbox Code Playgroud)

javascript event-loop node.js

4
推荐指数
1
解决办法
1195
查看次数

查询以检查记录是否存在于Spring Jdbc模板中

我对Spring还是很陌生,我想检查数据库中是否存在某个电子邮件ID,或者不使用Spring Jdbc模板,我在这里查看但找不到正确的答案。SELECT count(*) from table where email=?

任何帮助将不胜感激。

spring jdbctemplate

3
推荐指数
1
解决办法
5355
查看次数

使用 Spring Security 时 Bootstrap 不起作用

我目前正在研究 Spring Boot 并致力于一个小型示例项目。但是由于将 Bootstrap 与 Spring-Boot-Security 包一起使用,我面临着一个非常令人困惑的问题。当我使用以下代码时,页面不会与 Bootstrap 一起显示。

我的 SecurityConfiguration.java 看起来像这样

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
            .authorizeRequests().antMatchers("/","/products","/product/show/*","/console/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin().loginPage("/login").permitAll()
            .and()
            .logout().permitAll();

        httpSecurity.csrf().disable();
        httpSecurity.headers().frameOptions().disable();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
            .withUser("admin").password("{noop}admin").roles("ADMIN")
            .and().withUser("user").password("{noop}user").roles("USER");
    }
}
Run Code Online (Sandbox Code Playgroud)

开发控制台网络

我认为有点令人困惑的是我得到了 301/ 未修改,但是当我尝试这样做以防止我缓存问题时,我完全重新打开了浏览器并使用了一个私人窗口。

当我禁用几乎所有安全功能时,我的页面会使用 Bootstrap 正确呈现。

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc spring-security twitter-bootstrap-3 spring-boot

3
推荐指数
1
解决办法
3297
查看次数