我有一个Spring Boot(V 1.3.5)Web应用程序,JSP打包为jar。视图位于src/main/resources/META-INF/resources/WEB-INF/views
。
有关该主题的信息,请参阅http://hillert.blogspot.lu/2016/03/spring-boot-with-jsp-in-executable-jar.html。
这适用于我的Fedora dev。工作站,以及Windows 7的同事,都使用Eclipse Mars。
但是在另一台Windows 8 PC上,在Eclipse或STS中运行相同的源代码会生成404,因为找不到任何视图,这会让我的头脑严肃起来。
我在这里附加了我的配置类,也许有人知道这里可能出现什么问题。
package our.base.package;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Profile;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableScheduling
@EnableCaching
//@EnableWebMvc
@ComponentScan(basePackages = { "our.base.package" })
public class SpringConfigRootApplication extends WebMvcConfigurerAdapter {
@Bean
public LocaleResolver localeResolver() {
final CookieLocaleResolver slr = new CookieLocaleResolver();
slr.setCookieMaxAge(86400 * 365 * 5);
slr.setCookieName("lang");
slr.setDefaultLocale(Locale.GERMAN);
return slr;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
final LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
lci.setIgnoreInvalidLocale(true);
return lci;
}
@Override
public void addInterceptors(final InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
@Bean
public InternalResourceViewResolver getInternalResourceViewResolver() {
final InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
resolver.setRequestContextAttribute("requestContext");
resolver.setExposeContextBeansAsAttributes(true);
return resolver;
}
@Bean(initMethod = "init", destroyMethod = "shutdown")
@Order(value = Ordered.LOWEST_PRECEDENCE)
public Application application() {
return new Application();
}
}