2015-04-08 2 views
4

Я новичок в Spring Boot, и у меня серьезные проблемы с этим. Существует короткий список связанных с Velocity Spring Boot свойств, которые я могу установить в application.properties, и они работают нормально. Но есть огромное количество свойств Velocity, которые я не могу настроить таким образом.Как правильно настроить скорость с помощью Spring Boot?

Я нашел this вопрос, который, кажется, адресует то, что мне нужно, но он не работает для меня. Когда я использую точки останова в Spring Boot во время запуска программы, я вижу, что пары ключ/значение «spring.velocity.properties. *» Считываются и загружаются Spring Spring правильно - они просто не влияют ни на что. Независимо от того, какое значение я им устанавливаю, поведение времени выполнения Velocity в любом случае использует значение по умолчанию.

Что мне не хватает?

EDIT:

pom.xml

<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>docuvore</groupId> 
<artifactId>docuvore-server</artifactId> 
<version>0.0.1-SNAPSHOT</version> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.0.BUILD-SNAPSHOT</version> 
</parent> 

<properties> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 

    <!-- Core Spring Boot --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 

    <!-- Tomcat and Spring Web MVC --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <!-- Spring Security 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-security</artifactId> 
    </dependency> 
    --> 

    <!-- Spring Data and MongoDB --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-mongodb</artifactId> 
    </dependency> 

    <!-- Apache Velocity --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-velocity</artifactId> 
    </dependency> 

    <!-- Project Lombok --> 
    <dependency> 
     <groupId>org.projectlombok</groupId> 
     <artifactId>lombok</artifactId> 
     <version>1.16.2</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

<!-- Additional lines to be added here... --> 

<!-- (you don't need this if you are using a .RELEASE version) --> 
<repositories> 
    <repository> 
     <id>spring-snapshots</id> 
     <url>http://repo.spring.io/snapshot</url> 
     <snapshots><enabled>true</enabled></snapshots> 
    </repository> 
    <repository> 
     <id>spring-milestones</id> 
     <url>http://repo.spring.io/milestone</url> 
    </repository> 
</repositories> 
<pluginRepositories> 
    <pluginRepository> 
     <id>spring-snapshots</id> 
     <url>http://repo.spring.io/snapshot</url> 
    </pluginRepository> 
    <pluginRepository> 
     <id>spring-milestones</id> 
     <url>http://repo.spring.io/milestone</url> 
    </pluginRepository> 
</pluginRepositories> 
</project> 

application.properties

logging.path=/logs 
#spring.velocity.resourceLoaderPath = /templates/ 
#spring.velocity.checkTemplateLocation=false 
spring.velocity.properties.template.provide.scope.control = true 
spring.velocity.properties.directive.parse.max.depth = 9 
spring.velocity.properties.runtime.log = C:/logs/velocity.log 

Application.java

package com.github.docuvore.prototype; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 
import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 

@Configuration 
@EnableAutoConfiguration 
@ComponentScan 
public class Application { 

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

ExampleVelocityController.java

package com.github.docuvore.prototype.examples; 

import java.io.StringWriter; 
import java.util.ArrayList; 
import java.util.List; 

import org.apache.velocity.Template; 
import org.apache.velocity.VelocityContext; 
import org.apache.velocity.app.VelocityEngine; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RestController; 

@RestController 
public class ExampleVelocityController { 

    @RequestMapping("/exampleVelocity") 
    String home() { 
     String result = null; 

     VelocityEngine velocity = new VelocityEngine(); 
     velocity.init(); 
     Template template = velocity.getTemplate("src/main/resources/templates/general/htmlElement.vm"); 

     VelocityContext context = new VelocityContext(); 
     context.put("title", "Apache Velocity"); 

     StringWriter writer = new StringWriter(); 
     template.merge(context, writer); 

     result = writer.toString(); 

     return result; 
    } 
} 

htmlElement.vm

<html> 
#parse ("src/main/resources/templates/general/bodyElement.vm") 
</html> 

bodyElement.vm

<body> 
#parse ("src/main/resources/templates/general/bodyElement.vm") 
</body> 

ответ

5

Вы должны поставить точку останова в VelocityAutoConfiguration для обеспечения используется, что скорость.

Посмотрите на spring-boot-sample-velocity. Проверьте зависимости.

+0

Скорость определенно используется, я могу работать с ней просто отлично, и я могу видеть прямые свойства скорости весенней загрузки, такие как spring.velocity.resourceLoaderPath или spring.velocity.checkTemplateLocation, используемые в VelocityAutoConfiguration. Единственное, что я не могу сделать, это получить Velocity, настроенный свойствами стиля spring.velocity.properties. [NativeVelocityProperty]. К сожалению, этот образец не используется, потому что он не пытается делать то же самое, что и я. – wMattDodd

+1

Конец во 2-й ссылке говорит «Недостаточная поддержка скорости». Подробнее здесь: https://github.com/spring-projects/spring-boot/commit/86d87f6b8ad6816b1d98bad7ab68bcdad1bf5cf0 – emecas