sdeleuze / spring-boot-kotlin-demo Goto Github PK
View Code? Open in Web Editor NEWSpring Boot Kotlin project with a REST Webservice and Spring Data
Home Page: https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin
Spring Boot Kotlin project with a REST Webservice and Spring Data
Home Page: https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin
I can't find the config file for datasource's properties?
Best wishes!
downloaded project, did gradle bootRun and got this:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-10-20 13:21:11.329 ERROR 6929 --- [ main] o.s.boot.SpringApplication : Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:583) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:858) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:122) ~[spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M5.jar:2.0.0.M5]
at hello.ApplicationKt.main(Application.kt:52) [main/:na]
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final]
at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:208) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:163) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:51) ~[spring-orm-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:358) ~[spring-orm-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:384) ~[spring-orm-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1763) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1700) ~[spring-beans-5.0.0.RELEASE.jar:5.0.0.RELEASE]
... 16 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) ~[na:na]
... 26 common frames omitted
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/usr/lib/jvm/java-9-oracle/bin/java'' finished with non-zero exit value 1
Compiling and running the demo with Java 8 is fine, but as soon as Java 9 I encounter the following error:
./gradlew bootRun
> Configure project :
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class org.gradle.api.Project, unresolved supertypes: Comparable<Project>
class org.gradle.api.plugins.ExtensionAware, unresolved supertypes: Object
class org.gradle.api.plugins.PluginAware, unresolved supertypes: Object
class groovy.lang.Closure, unresolved supertypes: Cloneable, Runnable, Serializable
class groovy.lang.GroovyObjectSupport, unresolved supertypes: Object
class groovy.lang.GroovyObject, unresolved supertypes: Object
class groovy.lang.GroovyCallable, unresolved supertypes: Callable<V>
class org.gradle.api.Action, unresolved supertypes: Object
class org.gradle.api.NamedDomainObjectFactory, unresolved supertypes: Object
class org.gradle.api.initialization.dsl.ScriptHandler, unresolved supertypes: Object
class org.gradle.api.NamedDomainObjectList, unresolved supertypes: List<T>
class org.gradle.api.DomainObjectCollection, unresolved supertypes: Collection<T>
class org.gradle.util.Configurable, unresolved supertypes: Object
class org.gradle.api.artifacts.dsl.DependencyHandler, unresolved supertypes: Object
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'spring-boot-kotlin-demo'.
> Could not open cache directory 7ooj87our40tvw5ni3o9390ur (/Users/niko/.gradle/caches/4.2/gradle-kotlin-dsl/7ooj87our40tvw5ni3o9390ur).
> Internal error: unable to compile script, see log for details
my environment looks like:
./gradlew --version
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/niko/.gradle/wrapper/dists/gradle-4.2-bin/cl9xe1l8k8ophj72k8rv6xbu7/gradle-4.2/lib/groovy-all-2.4.11.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
------------------------------------------------------------
Gradle 4.2
------------------------------------------------------------
Build time: 2017-09-20 14:48:23 UTC
Revision: 5ba503cc17748671c83ce35d7da1cffd6e24dfbd
Groovy: 2.4.11
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 9 (Oracle Corporation 9+181)
OS: Mac OS X 10.11.6 x86_64
and how about findByLastName
fun works?
Best wishes
ChenKan
Maybe i'm missing something, but I get the following error when trying to build.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/toilal/idea-projects/spring-boot-kotlin-demo/build.gradle.kts' line: 2
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.0.0.M5', artifact: 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M5'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Gradle Central Plugin Repository (plugin 'org.springframework.boot' has no version '2.0.0.M5' - see https://plugins.gradle.org/plugin/org.springframework.boot for available versions)
- maven(https://jcenter.bintray.com/) (Could not resolve plugin artifact 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M5')
- maven(https://repo.spring.io/milestone) (Could not resolve plugin artifact 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.M5')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s```
hi , Could you tell me how to solve this
FAILURE: Build failed with an exception.
* Where:
Build file '/home/lab/spring-boot-kotlin-demo/build.gradle.kts' line: 3
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.1.2.RELEASE'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.1.2.RELEASE')
Searched in the following repositories:
Gradle Central Plugin Repository
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
CONFIGURE FAILED in 9s
โ java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Thanks for this, and the great talk at https://www.infoq.com/presentations/servlet-reactive-stack
Minor suggestion. I used this as the starting point to experiment a little with Spring 2.0 and Kotlin, and was stuck for a bit trying to get anything from resources/static to load since "/" was already mapped to CustomerController
. It might be helpful to update the routes in CustomerController
as...
@RestController
class CustomerController(private val repository: CustomerRepository) {
@GetMapping("/customers")
fun findAll() = repository.findAll()
@GetMapping("/customers/{lastName}")
fun findByLastName(@PathVariable lastName:String)
= repository.findByLastName(lastName)
}
Thanks again...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.