小编Jer*_*rry的帖子

带有H2文件数据库的Spring Boot应用程序

我正在尝试在Spring启动应用程序启动时设置H2数据库.我在application.properties中配置了数据库:

spring.datasource.url = jdbc:h2:file:~/testdb
spring.datasource.username = sa
spring.datasource.password = sa
spring.datasource.driverClassName = org.h2.Driver
Run Code Online (Sandbox Code Playgroud)

Application.java文件:

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);

        CreateH2Database createH2Database = new CreateH2Database();
        createH2Database.create();
    }
}
Run Code Online (Sandbox Code Playgroud)

CreateH2Database.java:

public class CreateH2Database {

    private Logger log = Logger.getLogger(CreateH2Database.class);

    @Autowired
    protected JdbcTemplate jdbcTemplate;

    public void create() {
        log.info("Creating H2 Database");
        createUsers();
    }

    private void createUsers() {
        log.info("Creating users table");
        jdbcTemplate.execute("create table if not exists users (id serial, first_name varchar(255), last_name varchar(255))");
        String[] …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

Mac 上的 Maven 和 JDK 1.7

当我尝试使用 Maven 编译项目时,出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project webserverlog: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project webserverlog: Compilation failure
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Run Code Online (Sandbox Code Playgroud)

我的 JAVA_HOME 指向 JDK:

$ echo $JAVA_HOME
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home

$ $JAVA_HOME/bin/javac -version
javac …
Run Code Online (Sandbox Code Playgroud)

java macos maven-3 java-7

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

在 Spring 5 JPA findOne() 中获取 `Long 无法转换为 Example<S>`

我在argument mismatch; Long cannot be converted to Example<S>下面的代码中收到了 findOne 调用:

public Optional<AuditEvent> find(Long id) {
    return Optional.ofNullable(persistenceAuditEventRepository.findOne(id))
        .map(auditEventConverter::convertToAuditEvent);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码正在转换为 Spring 5 和 Spring Boot 2。它在原始 Spring 4 和 Spring Boot 1 应用程序中运行良好。

任何想法我需要将上述代码转换为什么?

spring spring-boot

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

JHipster 5可用性

JHipster 5(使用Spring Boot 2)可以玩吗?我注意到在发行说明中提到了关于JHipster 5的工作,但是看不到有关如何安装/运行5的"预览"版本的任何信息.

jhipster

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

Spring启动时使用构造函数参数初始化bean

我需要PointQuadTree在启动时使用带有构造函数参数的Spring Boot 初始化以下类,并使该对象在整个应用程序中可用.构造函数参数'minX,maxX,...'需要来自application.properties文件.

PointQuadTree

public class PointQuadTree<T extends PointQuadTree.Item> {

   private final Bounds mBounds;

   public PointQuadTree(double minX, double maxX, double minY, double maxY) {
      this(new Bounds(minX, maxX, minY, maxY));
   }

   ...

}
Run Code Online (Sandbox Code Playgroud)

边界

public class Bounds {
   public final double minX;
   public final double minY;

   public final double maxX;
   public final double maxY;

   public final double midX;
   public final double midY;

   public Bounds(double minX, double maxX, double minY, double maxY) {
      this.minX = minX;
      this.minY = minY;
      this.maxX …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

将“ Callable &lt;T&gt;” Java方法转换为Kotlin

我正在尝试转换Java方法:

private <T> Callable<T> createCallable(final Callable<T> task) {
    return () -> {
        try {
            return task.call();
        } catch (Exception e) {
            handle(e);
            throw e;
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

从以下Java文件ExceptionHandlingAsyncTaskExecutor.java进入Kotlin。

该代码使用IntelliJ IDEA自动转换为:

private fun <T> createCallable(task: Callable<T>): Callable<T> {
    return {
        try {
            return task.call()
        } catch (e: Exception) {
            handle(e)
            throw e
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是不正确的。但是我必须考虑应该采用哪种正确的实现方式。有任何想法吗?

kotlin

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

Java Stream with :: new to Kotlin

我正在尝试将以下Spring Security代码从Java转换为Kotlin.

Java的:

Collection<? extends GrantedAuthority> authorities =
        Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
            .map(SimpleGrantedAuthority::new)
            .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

科特林:

val authorities = Arrays.stream(claims[AUTHORITIES_KEY].toString().split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
        .map(SimpleGrantedAuthority())
        .collect(Collectors.toList<SimpleGrantedAuthority>())
Run Code Online (Sandbox Code Playgroud)

我得到一个类型不匹配错误(Required: Function<in String!, out (???..???)>!).map(SimpleGrantedAuthority()).如何::new正确地将上述Java代码转换为Kotlin ?

spring kotlin

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

Spring Boot 2.0.0中的'UndertowEmbeddedServletContainerFactory'在哪里?

我正在尝试将现有项目升级到Spring 5和Spring Boot 2.0.0.有一个扩展的类,UndertowEmbeddedServletContainerFactory应该在org.springframework.boot.context.embedded.undertow包中.但是,我在当前的Spring Boot 2.0.0.M1/M2/M3/BUILD-SNAPSHOT中看不到这个包或接口.文档似乎仍然引用了这个接口API文档.

这个界面是否被其他东西取代了?

原始代码:

import io.github.jhipster.config.JHipsterConstants;
import io.github.jhipster.config.JHipsterProperties;
import io.github.jhipster.web.filter.CachingHttpHeadersFilter;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.servlet.InstrumentedFilter;
import com.codahale.metrics.servlets.MetricsServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.embedded.*;
import org.springframework.boot.web.embedded.undertow.*;//.UndertowEmbeddedServletContainerFactory;
import io.undertow.UndertowOptions;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import javax.servlet.*;

/**
 * Configuration of web application with Servlet 3.0 APIs.
 */
@Configuration
public class WebConfigurer implements ServletContextInitializer, EmbeddedServletContainerCustomizer {

    private …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot

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

如何从String获取可选<String>?和Kotlin中的字符串

我已经在Kotlin中覆盖了一个返回一个函数的函数Optional<String>.我如何转换String?String输入Optional<String>

例:

override fun getCurrentAuditor(): Optional<String> {
    val userName = SecurityUtils.currentUserLogin
    return userName ?: SYSTEM_ACCOUNT
}
Run Code Online (Sandbox Code Playgroud)

从上面的例子:

userName 是一个 String?

SYSTEM_ACCOUNT 是一个 String

我在返回语句中遇到错误,两个变量都不是Optional<String>类型.

kotlin

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

标签 统计

spring ×5

spring-boot ×4

java ×3

kotlin ×3

java-7 ×1

jhipster ×1

macos ×1

maven-3 ×1