Add CLASSPATH elements back to spring CLI script

Also add @WebConfiguration as a shortcut for groovy
scripts to get MVC behaviour (without a @Controller)

[#54926366]
This commit is contained in:
Dave Syer 2013-08-12 15:40:19 +01:00
parent 8e347cddff
commit 0d583deb27
3 changed files with 33 additions and 2 deletions

View File

@ -16,12 +16,15 @@
package org.springframework.boot.autoconfigure.web; package org.springframework.boot.autoconfigure.web;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import javax.servlet.Servlet; import javax.servlet.Servlet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -99,6 +102,8 @@ public class WebMvcAutoConfiguration {
@EnableWebMvc @EnableWebMvc
public static class WebMvcAutoConfigurationAdapter extends WebMvcConfigurerAdapter { public static class WebMvcAutoConfigurationAdapter extends WebMvcConfigurerAdapter {
private static Log logger = LogFactory.getLog(WebMvcConfigurerAdapter.class);
@Autowired @Autowired
private ListableBeanFactory beanFactory; private ListableBeanFactory beanFactory;
@ -162,6 +167,12 @@ public class WebMvcAutoConfiguration {
private void addStaticIndexHtmlViewControllers(ViewControllerRegistry registry) { private void addStaticIndexHtmlViewControllers(ViewControllerRegistry registry) {
for (String resource : STATIC_INDEX_HTML_RESOURCES) { for (String resource : STATIC_INDEX_HTML_RESOURCES) {
if (this.resourceLoader.getResource(resource).exists()) { if (this.resourceLoader.getResource(resource).exists()) {
try {
logger.info("Adding welcome page: "
+ this.resourceLoader.getResource(resource).getURL());
}
catch (IOException e) {
}
registry.addViewController("/").setViewName("/index.html"); registry.addViewController("/").setViewName("/index.html");
return; return;
} }

View File

@ -79,7 +79,13 @@ if [ ! -d "${SPRING_HOME}" ]; then
exit 2 exit 2
fi fi
CLASSPATH="${SPRING_HOME}/lib/*" CLASSPATH=.:${SPRING_HOME}/bin
if [ -d ${SPRING_HOME}/ext ]; then
CLASSPATH=$CLASSPATH:${SPRING_HOME}/ext
fi
for f in ${SPRING_HOME}/lib/*; do
CLASSPATH=$CLASSPATH:$f
done
if $cygwin; then if $cygwin; then
SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"` SPRING_HOME=`cygpath --path --mixed "$SPRING_HOME"`

View File

@ -16,6 +16,12 @@
package org.springframework.boot.cli.compiler.autoconfigure; package org.springframework.boot.cli.compiler.autoconfigure;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.AstUtils; import org.springframework.boot.cli.compiler.AstUtils;
@ -47,7 +53,8 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio
@Override @Override
public boolean matches(ClassNode classNode) { public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "Controller", "EnableWebMvc"); return AstUtils.hasAtLeastOneAnnotation(classNode, "Controller", "EnableWebMvc",
"WebConfiguration");
} }
@Override @Override
@ -58,6 +65,13 @@ public class SpringMvcCompilerAutoConfiguration extends CompilerAutoConfiguratio
"org.springframework.web.servlet.handler", "org.springframework.http"); "org.springframework.web.servlet.handler", "org.springframework.http");
imports.addStaticImport("org.springframework.boot.cli.template.GroovyTemplate", imports.addStaticImport("org.springframework.boot.cli.template.GroovyTemplate",
"template"); "template");
imports.addImports(WebConfiguration.class.getCanonicalName());
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
@Documented
public static @interface WebConfiguration {
} }
} }