0
votes

I have a very simple Spring Boot application with classes detailed below.

My problem is with the application.properties file and how they get auto-configured. I'm trying to get Groovy Templates to update in dev by setting 'spring.groovy.template.cache: false', however this is not working. I added two more properties to see if the application.properties file was being read. The 'logging.level.org.springframework.web: ERROR' still results in INFO level messages printed to the console. However, some.prop is read correctly into the MyBean class on application start.

Is there a configuration declaration I'm missing for these properties?

src/main/resources/application.properties:

spring.groovy.template.cache: false
logging.level.org.springframework.web: ERROR
some.prop: bob

src/main/java/sample/MyBean.java:

@Component
public class MyBean {

    @Value("${some.prop}")
    private String prop;

    public MyBean() {}

    @PostConstruct
    public void init() {
        System.out.println("================== " + prop + "================== ");
    }
}

and src/main/java/sample/Application.java:

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

and src/main/java/sample/com/example/MainController.java

@Controller
public class MainController {

    @RequestMapping(value="/login", method = RequestMethod.GET)
    public ModelAndView risk(@RequestParam Optional<String> error) {
        return new ModelAndView("views/login", "error", error);
    }

}
2
I never used the ":", perhaps it is not accepted for some parameters and you need to specify "=" instead ? - Marged
Marged is right. The colon is used with YAML, properties files need an equals sign - hyness
They should work exactly the same. In fact, the springboot example projects on Github (spring-boot/spring-boot-samples/spring-boot-sample-web-groovy-templates) use ':' in their application.properties files. However, I did test and it still does not function properly with '=' . - Brandon Wagner
Are you only using auto config or do you have some custom configuration that interferes/disables auto configuration? - M. Deinum
There shouldn't be anything disabling or interfering. The Application.java is the only src file I have other than one controller (edited question with controller). - Brandon Wagner

2 Answers

0
votes

It seems you missing scanned your package "sample". Please make sure that you have scanned it.

@ComponentScan({
     "sample" })
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Also, your application.properties is right. No problem with it.

0
votes

It appears the solution was much simpler than I thought:

gradle bootRun 

should be used to hot reload templates

gradle run does not work (all compiled classes are just built in build/ )