标签: spring-boot

方法org.postgresql.jdbc.PgConnection.createClob()尚未实现

我该如何解决这个错误:

java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation(LobCreatorBuilderImpl.java:113) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.makeLobCreatorBuilder(LobCreatorBuilderImpl.java:54) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:271) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:861) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:888) [hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:388) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) [spring-orm-5.0.4.RELEASE.jar:5.0.4.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

java spring-boot

92
推荐指数
7
解决办法
4万
查看次数

以编程方式关闭Spring Boot应用程序

如何在不终止VM的情况下以编程方式关闭Spring Boot应用程序?

在其他作品中,与之相反

new SpringApplication(Main.class).run(args);
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

91
推荐指数
4
解决办法
8万
查看次数

如何使用Eclipse调试Spring Boot应用程序?

我的Spring Bootwebapp运行得很好,我想通过Eclipse调试它.

因此,在启动我的远程Java应用程序调试器时,我应该收听哪个端口?我的webapp上有一个设置我必须设置为启用调试吗?

java eclipse debugging spring spring-boot

91
推荐指数
8
解决办法
16万
查看次数

加快Spring Boot启动时间

我有一个Spring Boot应用程序.我添加了很多依赖项(不幸的是,看起来我需要所有这些依赖项)并且启动时间上升了很多.只SpringApplication.run(source, args)需要10秒钟.

虽然这与"使用"相比可能没那么多,但我很不高兴它需要那么多,主要是因为它打破了开发流程.此时应用程序本身相当小,所以我假设大部分时间都与添加的依赖项有关,而不是与应用程序类本身有关.

我假设问题是类路径扫描,但我不知道如何:

  • 确认是问题(即如何"调试"Spring Boot)
  • 如果它真的是原因,我怎么能限制它,所以它变得更快?例如,如果我知道某些依赖项或包不包含Spring应扫描的任何内容,是否有办法限制它?

我假设这个:

会加快速度,但现在甚至都没有进行分类.我在Spring Boot本身看到了一些其他的努力,例如:

但这看起来特定于Tomcat.

本文:

虽然针对集成测试,建议使用lazy-init=true,但是我不知道如何使用Java配置将这个应用于Spring Boot中的所有bean - 这里有任何指针吗?

任何(其他)建议都会受到欢迎.

java performance startup spring-boot

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

spring boot添加http请求拦截器

在Spring启动应用程序中添加HttpRequest拦截器的正确方法是什么?我想要做的是为每个http请求记录请求和响应.

Spring启动文档根本不涉及此主题.(http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/)

我发现了一些关于如何对旧版本的spring执行相同操作的Web示例,但这些示例与applicationcontext.xml一起使用.请帮忙.

java spring spring-mvc spring-boot

90
推荐指数
7
解决办法
13万
查看次数

使用YAML的Spring @PropertySource

Spring Boot允许我们用YAML等价物替换我们的application.properties文件.但是我的测试似乎遇到了麻烦.如果我注释我的TestConfiguration(一个简单的Java配置),它期望一个属性文件.

例如,这不起作用: @PropertySource(value = "classpath:application-test.yml")

如果我在我的YAML文件中有这个:

db:
  url: jdbc:oracle:thin:@pathToMyDb
  username: someUser
  password: fakePassword
Run Code Online (Sandbox Code Playgroud)

我会用这样的东西来利用这些价值观:

@Value("${db.username}") String username
Run Code Online (Sandbox Code Playgroud)

但是,我最终得到了错误:

Could not resolve placeholder 'db.username' in string value "${db.username}"
Run Code Online (Sandbox Code Playgroud)

我如何在测试中利用YAML的优点?

spring spring-boot

89
推荐指数
8
解决办法
9万
查看次数

Spring引导@ResponseBody不会序列化实体ID

有一个奇怪的问题,无法弄清楚如何处理它.有简单的POJO:

@Entity
@Table(name = "persons")
public class Person {

    @Id
    @GeneratedValue
    private Long id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "middle_name")
    private String middleName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "comment")
    private String comment;

    @Column(name = "created")
    private Date created;

    @Column(name = "updated")
    private Date updated;

    @PrePersist
    protected void onCreate() {
        created = new Date();
    }

    @PreUpdate
    protected void onUpdate() {
        updated = new Date();
    }

    @Valid
    @OrderBy("id")
    @OneToMany(mappedBy = "person", fetch = FetchType.EAGER, cascade = …
Run Code Online (Sandbox Code Playgroud)

java spring json spring-boot

89
推荐指数
4
解决办法
3万
查看次数

如何自定义Spring Boot隐式使用的Jackson JSON映射器?

我正在使用Spring Boot(1.2.1),其方式与构建RESTful Web服务教程的方式类似:

@RestController
public class EventController {

    @RequestMapping("/events/all")
    EventList events() {
        return proxyService.getAllEvents();
    }

}
Run Code Online (Sandbox Code Playgroud)

所以上面,Spring MVC暗中使用Jackson将我的EventList对象序列化为JSON.

但我想对JSON格式进行一些简单的自定义,例如:

setSerializationInclusion(JsonInclude.Include.NON_NULL)
Run Code Online (Sandbox Code Playgroud)

问题是,自定义隐式JSON映射器的最简单方法什么?

我在这篇博客文章中尝试了这种方法,创建了一个CustomObjectMapper等等,但是第3步"在Spring上下文中注册类"失败了:

org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'jacksonFix': Injection of autowired dependencies failed; 
  nested exception is org.springframework.beans.factory.BeanCreationException: 
  Could not autowire method: public void com.acme.project.JacksonFix.setAnnotationMethodHandlerAdapter(org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter); 
  nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
  No qualifying bean of type [org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter]   
  found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc jackson spring-boot

89
推荐指数
8
解决办法
13万
查看次数

缺少CrudRepository#findOne方法

我在我的项目中使用Spring 5.直到今天还有可用的方法CrudRepository#findOne.

但下载最新快照后,它突然消失了!有没有提到该方法现在不可用?

我的依赖列表:

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}    

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-validation'
    compile 'org.springframework.boot:spring-boot-starter-web'
    compile 'org.springframework.boot:spring-boot-starter-data-jpa'
    runtime 'org.springframework.boot:spring-boot-devtools'

    runtime 'com.h2database:h2:1.4.194'
    compile 'org.projectlombok:lombok:1.16.14'
    compile 'org.modelmapper:modelmapper:0.7.5'


    testCompile 'org.springframework.boot:spring-boot-starter-test'

    testCompile 'org.codehaus.groovy:groovy-all:2.4.10'

    testCompile 'cglib:cglib:3.2.5'
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
}
Run Code Online (Sandbox Code Playgroud)

更新:

似乎这个方法已被替换 CrudRepository#findById

java spring spring-data spring-data-jpa spring-boot

89
推荐指数
4
解决办法
4万
查看次数

Spring Boot中的spring.jpa.open-in-view = true属性是什么?

我在Spring Boot文档中看到了JPA配置的这个属性spring.jpa.open-in-view=true.那么它被设置为true,它是默认值吗?

它到底意味着什么?我没有找到任何解释这种行为.

它应该是使用Hibernate SessionFactory来代替EntityManagerFactory?如果是,我该如何设置EntityManagerFactory

感谢任何帮助.

谢谢!

java spring jpa spring-data spring-boot

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