- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Spring-boot + Vaadin 创建一个 Web 项目,并且我想使用 spring-data-jpa 和 hibernate 从 PostgreSQL 数据库中获取数据。
在我的 Vaadin 看来,我尝试 Autowiring 我的服务类,但我总是得到 null 并且错误堆栈跟踪没有告诉我原因。
kotlin.UninitializedPropertyAccessException: lateinit property clientService has not been initialized at com.apache.vaadin.view.Index.getClientService(Index.kt:24) ~[classes/:na] at com.apache.vaadin.view.Index$readButton$1.buttonClick(Index.kt:40) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:211) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:174) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1029) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.ui.Button.fireClick(Button.java:370) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.ui.Button$1.click(Button.java:57) ~[vaadin-server-8.0.6.jar:8.0.6] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131] at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:155) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:116) ~[vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:445) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:410) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1464) [vaadin-server-8.0.6.jar:8.0.6] at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:381) [vaadin-server-8.0.6.jar:8.0.6] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.15.jar:8.5.15] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.15.jar:8.5.15] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.15.jar:8.5.15] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = arrayOf("com.apache.vaadin.model"))
@ComponentScan(basePackages = arrayOf("com.apache.vaadin.model"))
open class DataSourceConfig {
@Autowired
lateinit var environment: Environment
@Bean
open fun entityManagerFactory(): LocalContainerEntityManagerFactoryBean {
var entityManagerFactory: LocalContainerEntityManagerFactoryBean = LocalContainerEntityManagerFactoryBean()
entityManagerFactory.apply {
dataSource = dataSource()
setPackagesToScan("com.apache.vaadin.model")
var vendorAdapter: HibernateJpaVendorAdapter = HibernateJpaVendorAdapter()
vendorAdapter.apply {
setGenerateDdl(true)
setShowSql(true)
}
var properties: Properties = Properties()
properties.apply {
put("database.dialet", "org.hibernate.dialect.PostgreSQL95Dialect")
put("database.globally_quoted_identifiers", "false")
put("database.enable_lazy_load_no_trans", "true")
put("database.show_sql", "true")
}
jpaVendorAdapter = vendorAdapter
setJpaProperties(properties)
}
return entityManagerFactory
}
@Primary
@Bean
open fun dataSource(): DataSource {
var source: ComboPooledDataSource = ComboPooledDataSource()
source.apply {
driverClass = "org.postgresql.Driver"
jdbcUrl = "jdbc:postgresql://localhost:5432/ignite"
user = "postgres"
password = "1111"
acquireIncrement = 5
idleConnectionTestPeriod = 60
maxPoolSize = 20
minPoolSize = 10
initialPoolSize = 10
}
return source
}
@Bean
open fun transactionManager() : PlatformTransactionManager {
var manager: JpaTransactionManager = JpaTransactionManager()
manager.apply {
entityManagerFactory = entityManagerFactory().nativeEntityManagerFactory
}
return manager
}
@Bean
open fun exceptionTranslator(): PersistenceExceptionTranslationPostProcessor = PersistenceExceptionTranslationPostProcessor()
}
@SpringUI
@Title(value = "Apache")
class Navigator : UI() {
@Autowired
lateinit var viewProvider: SpringViewProvider
init {
}
private val INDEX = ""
override fun init(p0: VaadinRequest?) {
navigator = Navigator(this, this)
navigator.addProvider(viewProvider)
navigator.addView(INDEX, Index::class.java)
}
}
@UIScope
@SpringView
open class Index : VerticalLayout(), View {
private val logger: Logger = Logger.getLogger(Index::class.java)
@Autowired
lateinit var clientService: IClientService // <--- error is here
init {
var menuBar: MenuBar = MenuBar()
var file = menuBar.addItem("File", null, null)
file.addItem("Save", {_ -> logger.info("Save clicked")})
file.addItem("Load", {_ -> logger.info("Load clicked")})
file.addItem("Open", {_ -> logger.info("Open clicked")})
file.addItem("Close", {_ -> logger.info("Close clicked")})
var settings = menuBar.addItem("Settings", null, null)
settings.addItem("DataBase", {_ -> logger.info("DataBase clicked")})
addComponent(menuBar)
var createButton: Button = Button("Create", { _ -> logger.info("Create clicked")})
var readButton: Button = Button("Read", { _ -> logger.info(clientService.findAll())})
var updateButton: Button = Button("Update", { _ -> logger.info("Update clicked")})
var deleteButton: Button = Button("Delete", { _ -> logger.info("Delete clicked")})
addComponent(createButton)
addComponent(readButton)
addComponent(updateButton)
addComponent(deleteButton)
}
override fun enter(p0: ViewChangeListener.ViewChangeEvent?) {
Notification.show("Welcome to the main com.ignite.app.view")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.apache.vaadin</groupId>
<artifactId>ignite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ignite</name>
<description></description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<vaadin.version>8.0.6</vaadin.version>
<kotlin.version>1.1.3-2</kotlin.version>
<hibernate>5.2.9.Final</hibernate>
<hibernate-validator>5.4.1.Final</hibernate-validator>
<postgres>42.1.1</postgres>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jre8</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>${hibernate}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@NoRepositoryBean
interface IClientService : CrudRepository<Client, Long>
@Service
class ClientService : IClientService {
private val logger: Logger = Logger.getLogger(ClientService::class.java)
@Autowired
lateinit var clientRepository: ClientRepository
override fun delete(p0: Long?) {
clientRepository.delete(p0)
}
override fun delete(p0: MutableIterable<Client>?) {
clientRepository.delete(p0)
}
override fun delete(p0: Client?) {
clientRepository.delete(p0)
}
override fun <S : Client?> save(p0: MutableIterable<S>?): MutableIterable<S> = clientRepository.save(p0)
override fun <S : Client?> save(p0: S): S = clientRepository.save(p0)
override fun findAll(p0: MutableIterable<Long>?): MutableIterable<Client> = clientRepository.findAll(p0)
override fun findAll(): MutableIterable<Client> = clientRepository.findAll()
override fun exists(p0: Long?): Boolean = clientRepository.exists(p0)
override fun findOne(p0: Long?): Client = clientRepository.findOne(p0)
override fun count(): Long = clientRepository.count()
override fun deleteAll() {
clientRepository.deleteAll()
}
}
@Repository
interface ClientRepository : CrudRepository<Client, Long>
@SpringUI
@Title(value = "Apache")
class Navigator : UI() {
@Autowired
lateinit var viewProvider: SpringViewProvider
@Autowired
lateinit var index: Index// <-
private val INDEX = "index"
override fun init(p0: VaadinRequest?) {
navigator = Navigator(this, this)
navigator.addProvider(viewProvider)
navigator.addView(INDEX, index) // <-
}
}
@UIScope
@SpringView
@SpringComponent // <-
open class Index : VerticalLayout(), View {...}
最佳答案
这是因为您尝试访问 clientService
在 init
block ,你不应该这样做, Spring 依赖注入(inject)发生之后 对象已准备好创建。例如:
@Autowired
lateinit var clientService: IClientService
init{
// v--- `clientService` is not injected by spring yet.
clientService;
}
InitializingBean
对于spring组件的初始化,例如:
open class Index : VerticalLayout(), View, InitializingBean {
@Autowired
lateinit var clientService: IClientService
override fun afterPropertiesSet(){
//copy your init block code here
}
}
关于hibernate - @Autowired lateinit 属性 '' 尚未初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45199985/
我在 init block 中初始化响应但是抛出异常:/为什么? lateinit var response: MutableLiveData> init { response.valu
我想知道如何在 C# 中使用 后期初始化的 类字段和 可为空引用类型 。 想象一下下面的类: public class PdfCreator { private PdfDoc doc; p
我正在尝试使用注释@MockBean 初始化(通过模拟)两个对象 它似乎只有在我调用方法 mock(className) 时才有效,但由于我想在多个方法上使用模拟类,我不想在我的测试方法中重复相同的代
使用数据绑定(bind)、ViewModel、LiveData ( MVVM )。 在我的布局中有一个表单可以添加员工详细信息。 布局:
使用 Retrofit2 和 rxjava2 未在 Recyclerview 中设置 Gson 可转换数据,然后通过其订阅给出错误: UninitializedPropertyAccessExcept
我的 Kotlin Activity 中有 lateinit 属性,这是它的简化版本: class CreateNewListOfQuestions : AppCompatActivity() {
我有一个自定义的线性布局类,当我想创建这个类的实例时,我收到以下错误: lateinit 属性尚未初始化 我正在使用最新版本的 butterknife 库。 以下是我的 Kotlin 类: class
以下两种方法有什么区别或没有区别: 1. private lateinit var binding: ResultProfileBinding override fun onCreate(savedI
所以我想要实现的是稍后在主函数中设置顶级变量,但我不想让它成为一个肯定会破坏 Extension 的 lateinit var可变功能。 例如,此代码不起作用,因为扩展变量不支持 lateinit 修
如果我有一个 lateinit 变量,我可以检查它是否使用 (this::lateInitVar.isInitialized) 初始化,如 https://stackoverflow.com/a/47
关于这个问题已经有几个 QA,但对我来说,他们似乎在谈论不同的事情(大多数情况下是 Android 的 Kotlin + Dagger2),而不是应用我的具体案例。 我通过阅读 this blog p
成员 lateinit 变量初始化可以通过以下方式检查: class MyClass { lateinit var foo: Any ... fun doSomething()
以下 Kotlin 代码有效 val (x, y) = getSomeXYPair() 但是你不能用 lateinit 全局变量来做到这一点 class Foo { private latei
当我运行从 Firebase github 存储库下载的 quickstart-Android Firebase 数据库入门应用程序时,无论我选择(通过对话框)运行 Java 版本还是 Kotlin
您好,当我使用 Kotlin 编写 Android 程序时,我在代码中看到了 lateinit。 Java 中的等价物是什么?如何将此代码从 Kotlin 更改为 Java? public class
我想知道是否有办法检查 lateinit 变量是否已初始化。例如: class Foo() { private lateinit var myFile: File fun bar(pa
我是 Android 的新手,我正在尝试使用 Dagger2 和 MVVM 模式以及 kotlin 创建一个应用程序,但我无法让它运行。 我的应用类代码。 class PruebaDaggerApp:
我在 BreakingNewsFragment 中使用这一行 viewModel = (activity as NewsActivity).viewModel 初始化了 viewModel,但是收到以
我知道有类似的问题,但我只是找不到类似的东西,我一直在学习新的东西来学习,同时将 kotlin 合成转换为 viewvbinding模式,我遇到了这个错误 kotlin.UninitializedPr
我在尝试将环境变量值分配给 lateinit 变量时遇到错误。错误是“原始类型的属性不允许'lateinit'修饰符”。 我的application.properties(读取环境变量) my.pro
我是一名优秀的程序员,十分优秀!