小编bti*_*nay的帖子

JDBC和JDBI有什么区别?

我想知道java中JDBCJDBI之间的区别.特别是,哪一个通常更好,为什么?

java jdbc jdbi

40
推荐指数
5
解决办法
3万
查看次数

什么是私人包裹的交易?

我一直在与OSGi合作一段时间,但我仍然不了解私有包.

  • 导出的包是其他包可见的包
  • 导入的包是由导出包的包导入的包.
  • 私有包是其他包不可见的包(我不明白)

并非所有未导出的捆绑包对所有其他包都不可见吗?如果是这样,那么未导出的私有包和包有什么区别?

我已经阅读了OSGi in Action和"OSGi和Apache Felix 3.0 - 初学者指南",但我无法找到差异.

java osgi module

26
推荐指数
2
解决办法
7704
查看次数

并行启动多个Gradle"spring-boot"插件"bootRun"任务

我有一个使用Gradle构建的多项目Spring Boot应用程序.我正在尝试做的是从命令行subprojects使用Spring Boot的bootRun任务来运行各种各样的"ad-hoc"测试gradle bootRun.但是,似乎每个守护进程按顺序启动和停止.有没有办法让我的所有Boot守护进程使用spring-boot插件并行运行?

任何建议将不胜感激 :)

java spring gradle spring-boot

15
推荐指数
1
解决办法
4104
查看次数

如何使用Spring Security OAuth2在Spring Boot中注册自定义BasicAuthenticationFilter AuthenticationProvider

上下文

我正在开发一个应用程序,允许经过身份验证的用户创建OAuth2承载令牌,以便与组织发布的API一起使用.这个想法是允许用户自己生成/撤销这样的令牌,类似于GitHub的Personal API令牌.然后,用户可以使用发布的令牌获得对受保护资源的编程访问.在此配置中,OAuth"客户端","授权服务器"和"资源服务器"属于组织.目前,所有这些服务都驻留在同一个流程中.

为此,我正在尝试支持资源所有者密码凭据授予类型.实施环境包括以下内容:

  • 春季启动
  • Spring Security OAuth2

实现的一个约束是无法访问存储的密码.此处理委托给执行实际身份验证的内部Web服务.

问题

由于无法访问存储密码的限制,因此无法使用默认配置,DaoAuthenticationProvider因为它需要访问UserDetails由提供程序返回的对象提供的密码UserDetailsService.

我的猜测是我需要AuthenticationProvider用自定义实现替换它.但是,所有这样做的尝试似乎都没有生效.

以下似乎在parent引用中正确注册AuthenticationManager,但未在运行时委托(由于DaoAuthenticationProvider优先权):

@Configuration
public class SecurityConfig extends GlobalAuthenticationConfigurerAdapter {

  @Override
  public void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.authenticationProvider(new AuthenticationProvider() {

      @Override
      public boolean supports(Class<?> authentication) {
        // For testing this is easier, but should check for UsernamePasswordAuthentication.class
        return true;
      }

      @Override
      public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        // …
Run Code Online (Sandbox Code Playgroud)

spring-security basic-authentication spring-boot spring-security-oauth2

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

如何在Spring Boot中禁用logback ConsoleAppender

我正在使用Spring Boot构建命令行应用程序.在此类应用程序中,日志记录控制台日志记录不合适.如何完全禁用控制台appender,但仍然使用默认的Spring Boot支持文件appender ?

更新

我在这里创建了一个功能请求,以便更简单地支持此功能:

https://github.com/spring-projects/spring-boot/issues/1612

logback spring-boot

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

如何从maven导入范围中排除spring-boot-dependencies的传递依赖性

根据文档,我在Spring Boot应用程序pom中有以下内容:

  <dependencyManagement>
    <dependencies>
      <!-- Spring -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

我需要使用dependencyManagement,<scope>import</scope>因为我需要使用标准的企业基础pom.

但是,似乎不可能排除传递依赖性spring-boot-dependencies.在我的特殊情况下,Spring Boot 1.2.1.RELEASE引入了一个Jetty版本,这个版本对我的其他版本来说太新了<dependencies>.我尝试使用<exclusion>以下形式:

  <dependencyManagement>
    <dependencies>
      <!-- Spring -->
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>

        <!-- Doesn't work -->
        <exclusions>
          <exclusion>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>*</artifactId>
          </exclusion>
        </exclusions>

      </dependency>

    </dependencies>
  </dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

使用Maven 3.2.1的通配符支持,但它似乎没有生效.

除了显式覆盖所有Jetty依赖项之外,是否有解决此问题的方法?有许多Jetty库,这种方法会非常脆弱.此外,我似乎也需要对Jetty的传递依赖性做同样的事情.

maven spring-boot

7
推荐指数
2
解决办法
3676
查看次数

如何防止Spring Boot用点解析YAML键

我有一个YAML配置文件,其中包含属性映射:

properties:
  a.b.c: 1
Run Code Online (Sandbox Code Playgroud)

Boot将解析为:

{a:{b:{c:1}}}
Run Code Online (Sandbox Code Playgroud)

但是,我想要的是:

{'a.b.c': 1}
Run Code Online (Sandbox Code Playgroud)

反正有没有把它哄进"通过"键模式?引用密钥似乎没有帮助.


更新

下面的实际例子.

Java的

import static com.google.common.collect.Maps.newLinkedHashMap;

import java.util.Map;
import javax.annotation.PostConstruct;

import lombok.Data;
import lombok.val;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties("hadoop")
public class HadoopProperties {

   private Map<Object, Object> properties = newLinkedHashMap();

}
Run Code Online (Sandbox Code Playgroud)

YAML

application.yml:

hadoop:
   properties:
      fs.defaultFS: hdfs://localhost:8020
      mapred.job.tracker: localhost:8021
Run Code Online (Sandbox Code Playgroud)

结果

调用toString()生成的对象:

HadoopProperties(properties = {fs = {defaultFS = hdfs:// localhost:8020},mapred = {job = {tracker = localhost:8021}}})

yaml snakeyaml spring-boot

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

如何使用Spring Boot和Spring Security OAuth2实现“个人访问令牌”

我正在尝试创建一个应用程序,该应用程序允许经过身份验证的用户创建OAuth2承载令牌,以与组织发布的API一起使用。这个想法是允许用户自行生成/撤销此类令牌,​​类似于GitHub的Personal API令牌。然后,用户可以使用发出的令牌来获得对同一组织公开的受保护资源的编程访问。

此应用程序需要:

  • 用于验证用户身份并允许用户生成和撤消令牌的UI
  • 服务器端RESTful API,允许用户身份验证以及令牌生成,吊销和存储

理想情况下,此应用程序将使用SPA是无状态的,并且不需要会话。

有关实现的一些问题:

  • 公开的API是否应该是@EnableAuthorizationServer /oauth/token使用“ 资源所有者密码凭证授予”类型的端点?如果是这样,将客户端凭据公开给UI是否不安全?可以避免吗?
  • API是否应公开直接调用的新的专用端点AuthorizationServerTokenServices?如果是这样,将如何实现?
  • 是否有使用Spring Boot和Spring Security OAuth2的参考实现?

任何建议或参考将不胜感激。

oauth-2.0 spring-boot spring-security-oauth2

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

SPARQL仅搜索xsd:integer,无小数

使用以下查询:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://localhost/SemanticSearch/semanticsearch.owl#>

SELECT
    DISTINCT * 
WHERE {
    ?uri uni:altLabel "5"^^xsd:integer.
    ?uri rdf:type ?type
}
Run Code Online (Sandbox Code Playgroud)

也返回其具有的URI altLabelxsd:decimal5.x的我真的需要它来只返回?uri具有altLabelxsd:integer.反正有没有实现这个目标?

rdf owl pellet sparql jena

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

Spark Task不能使用简单的累加器进行序列化?

我正在运行这个简单的代码:

val accum = sc.accumulator(0, "Progress");
listFilesPar.foreach {
  filepath =>
    accum += 1
}
Run Code Online (Sandbox Code Playgroud)

listFilesPar是一个 RDD[String]

这会引发以下错误:

org.apache.spark.SparkException: Task not serializable
Run Code Online (Sandbox Code Playgroud)

现在我不明白发生了什么,我没有括号括号,因为我需要写一个冗长的函数.我只是做单元测试

scala accumulator apache-spark

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