File tree Expand file tree Collapse file tree
src/main/kotlin/de/tschuehly/spring/viewcomponent/core Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ repositories {
2525dependencies {
2626 implementation(" org.springframework.boot:spring-boot-starter-web" )
2727 implementation(" org.springframework.boot:spring-boot-starter-aop" )
28- implementation (" org.springframework.boot:spring-boot-devtools" )
28+ compileOnly (" org.springframework.boot:spring-boot-devtools" )
2929 implementation(" io.projectreactor:reactor-core" )
3030 implementation(" com.fasterxml.jackson.module:jackson-module-kotlin" )
3131 implementation(" org.jetbrains.kotlin:kotlin-reflect" )
Original file line number Diff line number Diff line change 11package de.tschuehly.spring.viewcomponent.core
22
3- import de.tschuehly.spring.viewcomponent.core.component.ViewComponent
43import de.tschuehly.spring.viewcomponent.core.component.ViewComponentProperties
4+ import de.tschuehly.spring.viewcomponent.core.condition.DevToolsExistsCondition
55import de.tschuehly.spring.viewcomponent.core.processor.ViewComponentChangeListener
66import org.slf4j.Logger
77import org.slf4j.LoggerFactory
8- import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
98import org.springframework.boot.context.properties.EnableConfigurationProperties
109import org.springframework.boot.devtools.filewatch.FileSystemWatcher
1110import org.springframework.context.ApplicationContext
1211import org.springframework.context.annotation.Bean
1312import org.springframework.context.annotation.ComponentScan
13+ import org.springframework.context.annotation.Conditional
1414import org.springframework.context.annotation.Configuration
1515import java.io.File
1616
@@ -20,7 +20,7 @@ import java.io.File
2020class ViewComponentAutoConfiguration {
2121
2222 @Configuration
23- @ConditionalOnProperty( " spring.view-component.local-development " )
23+ @Conditional( DevToolsExistsCondition :: class )
2424 class LocalDevConfig {
2525 val logger: Logger = LoggerFactory .getLogger(LocalDevConfig ::class .java)
2626
Original file line number Diff line number Diff line change 1+ package de.tschuehly.spring.viewcomponent.core.condition
2+
3+ import org.slf4j.Logger
4+ import org.slf4j.LoggerFactory
5+ import org.springframework.context.annotation.Condition
6+ import org.springframework.context.annotation.ConditionContext
7+ import org.springframework.core.type.AnnotatedTypeMetadata
8+
9+ class DevToolsExistsCondition : Condition {
10+ private val logger : Logger = LoggerFactory .getLogger(DevToolsExistsCondition ::class .java)
11+ override fun matches (context : ConditionContext , metadata : AnnotatedTypeMetadata ): Boolean {
12+ val isLocalDevelopment = context.environment.getProperty(" spring.view-component.local-development" ).toBoolean()
13+ val isDevToolsExists = try {
14+ Class .forName(" org.springframework.boot.devtools.restart.Restarter" , false , context.classLoader)
15+ true
16+ } catch (e: ClassNotFoundException ) {
17+ logger.error(" In order to use hot-reload function, spring-dev-tools needed" )
18+ false
19+ }
20+
21+ return isLocalDevelopment && isDevToolsExists
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments