English | 简体中文
This is a sample project based on Solon + Kronos ORM + JDK 17 + Maven + Kotlin 2.1.0.
If you would like to learn more about Kronos, please visit Kronos.
If you built failed in Intellij IDEA and build with Maven, please try to enable the following setting: Settings / Build, Execution, Deployment / Build Tools / Maven / Runner / Delegate IDE build/run actions to Maven.
1. Add Kronos dependency
<repositories>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.kotlinorm</groupId>
<artifactId>kronos-core</artifactId>
<version>${kronos.version}</version>
</dependency>
</dependencies>2. Add Kotlin compiler plugin
<pluginRepositories>
<pluginRepository>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compilerPlugins>
<plugin>all-open</plugin>
<plugin>kronos-maven-plugin</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.kotlinorm</groupId>
<artifactId>kronos-maven-plugin</artifactId>
<version>${kronos.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>The sample project uses kronos-jdbc-wrapper, and you can configure the data source in the following way. You can also replace it with another wrapper or customize the wrapper.
@SolonMain
class App
@Inject("\${db.url}")
var dbUrl: String? = null
@Inject("\${db.username}")
var dbUsername: String? = null
@Inject("\${db.password}")
var dbPassword: String? = null
val wrapper by lazy {
KronosBasicWrapper(
BasicDataSource().apply {
url = dbUrl
username = dbUsername
password = dbPassword
}
)
}
fun main(args: Array<String>) {
Kronos.init {
dataSource = { wrapper }
fieldNamingStrategy = lineHumpNamingStrategy
tableNamingStrategy = lineHumpNamingStrategy
}
Solon.start(App::class.java, args)
}After running the project, visit the following URL to view the results:
http://localhost:8081
If the interface returns the results shown below, Kronos has run successfully and the compiler plugin is working properly.
