大佬教程收集整理的这篇文章主要介绍了java – Spring-boot UTF-8资源,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用spring-boot(我正在关注this tutorial),目前的代码是here.
我的应用程序是通过@EnableAutoConfiguration配置的,所以我没有web.xml或其他配置文件.
该应用程序有一个/ **的默认处理程序,来自projectRoot / src / main / webapp /的文件被提供,但遗憾的是Content-Type:text / html; charset = ISO-8859-1.我想用UTF-8字符集提供(html文件).
如我所知,静态文件也由spring提供:在启动应用程序之后,以下行在日志中显示:映射URL路径[/ **]到类型为[class org.springframework.web.servlet]的处理程序. resource.resourcehttprequestHandler](github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java#L182,抱歉,我不能发布2个以上的链接)
把< meta="" charset="“utf-8”/">或< meta="" http-equiv="“Content-Type:text" html;="" charset="utf-8”/">进入服务的html文件没有任何效果.
如何使用UTF-8字符集提供* .html文件?
调试日志如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__,| / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v0.5.0.M6)
2013-11-24 00:48:41.327 INFO 15786 --- [ main] Hello.Application : StarTing Application on ubuntu with PID 15786 (/home/lennon/bme/szoftarch/szoftarch-2013-osz/build/libs/gs-rest-service-0.1.0.jar started by lennon)
2013-11-24 00:48:41.331 DEBUG 15786 --- [ main] o.s.boot.SpringApplication : Loading source class Hello.Application
2013-11-24 00:48:41.380 INFO 15786 --- [ main] ationConfigEmbeddedWebApplicationContext : refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7455ffcd: startup date [Sun Nov 24 00:48:41 CET 2013]; root of context hierarchy
2013-11-24 00:48:41.385 DEBUG 15786 --- [ main] ationConfigEmbeddedWebApplicationContext : Bean factory for org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@7455ffcd: org.springframework.beans.factory.support.DefaultListablebeanfactory@54cb8484: defining beans [org.springframework.context.Annotation.internalConfigurationAnnotationProcessor,org.springframework.context.Annotation.internalAutowiredAnnotationProcessor,org.springframework.context.Annotation.internalrequiredAnnotationProcessor,org.springframework.context.Annotation.internalCommonAnnotationProcessor,application]; root of factory hierarchy
2013-11-24 00:48:42.179 DEBUG 15786 --- [ main] ationConfigEmbeddedWebApplicationContext : Using messagesource [org.springframework.context.support.resourceBundlemessagesource: basenames=[messages]]
2013-11-24 00:48:42.182 DEBUG 15786 --- [ main] ationConfigEmbeddedWebApplicationContext : Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@5d36368]
2013-11-24 00:48:42.518 DEBUG 15786 --- [ main] .t.tomcatEmbeddedServletContainerFactory : Code archive: /home/lennon/bme/szoftarch/szoftarch-2013-osz/build/libs/gs-rest-service-0.1.0.jar
2013-11-24 00:48:42.518 DEBUG 15786 --- [ main] .t.tomcatEmbeddedServletContainerFactory : Code archive: /home/lennon/bme/szoftarch/szoftarch-2013-osz/build/libs/gs-rest-service-0.1.0.jar
2013-11-24 00:48:42.518 DEBUG 15786 --- [ main] .t.tomcatEmbeddedServletContainerFactory : Document root: /home/lennon/bme/szoftarch/szoftarch-2013-osz/src/main/webapp
2013-11-24 00:48:42.904 INFO 15786 --- [ main] o.apache.catalina.core.Standardservice : StarTing service tomcat
2013-11-24 00:48:42.905 INFO 15786 --- [ main] org.apache.catalina.core.StandardENGIne : StarTing Servlet ENGIne: Apache tomcat/7.0.42
2013-11-24 00:48:43.006 INFO 15786 --- [ost-startStop-1] o.a.c.c.C.[tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2013-11-24 00:48:43.007 INFO 15786 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1630 ms
2013-11-24 00:48:43.259 INFO 15786 --- [ost-startStop-1] o.a.c.c.C.[tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2013-11-24 00:48:43.260 INFO 15786 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2013-11-24 00:48:43.428 INFO 15786 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequestHandler]
2013-11-24 00:48:43.717 INFO 15786 --- [ost-startStop-1] s.w.s.m.m.a.requestMappingHandlerMapping : Mapped "{[/greeTing],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public Hello.GreeTing Hello.GreeTingController.greeTing(java.lang.String)
2013-11-24 00:48:43.725 INFO 15786 --- [ost-startStop-1] o.s.w.s.c.a.WebMvcConfigurerAdapter : Adding welcome page: jndi:/localhost/index.html
2013-11-24 00:48:43.732 INFO 15786 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Root mapping to handler of type [class org.springframework.web.servlet.mvc.ParameterizableViewController]
2013-11-24 00:48:43.811 INFO 15786 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequestHandler]
2013-11-24 00:48:43.812 INFO 15786 --- [ost-startStop-1] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.resourcehttprequestHandler]
2013-11-24 00:48:44.489 INFO 15786 --- [ost-startStop-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 1229 ms
2013-11-24 00:48:44.641 DEBUG 15786 --- [ main] ationConfigEmbeddedWebApplicationContext : Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@10d6fc05]
2013-11-24 00:48:44.644 DEBUG 15786 --- [ main] nitializer$AutoConfigurationReportLogger :
=========================
AUTO-CONfigURATION REPORT
=========================
Positive matches:
-----------------
messagesourceAutoConfiguration
- @ConditionalOnMissingBean (types: org.springframework.context.messagesource; SearchStrategy: all) found no beans (OnBeanCondition)
PropertyPlaceholderAutoConfiguration#propertysourcesPlaceholderConfigurer
- @ConditionalOnMissingBean (types: org.springframework.context.support.PropertysourcesPlaceholderConfigurer; SearchStrategy: current) found no beans (OnBeanCondition)
DispatcherServletAutoConfiguration
- found web application StandardServletEnvironment (OnWebApplicationCondition)
- @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
- found web application StandardServletEnvironment (OnWebApplicationCondition)
- @ConditionalOnClass classes found: org.springframework.web.servlet.DispatcherServlet (OnClassCondition)
- @ConditionalOnBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: all) found the following [tomcatEmbeddedServletContainerFactory] (OnBeanCondition)
DispatcherServletAutoConfiguration#dispatcherServlet
- no DispatcherServlet found (DispatcherServletAutoConfiguration.DefaultDispatcherServletCondition)
EmbeddedServletContainerAutoConfiguration
- found web application StandardServletEnvironment (OnWebApplicationCondition)
- found web application StandardServletEnvironment (OnWebApplicationCondition)
EmbeddedServletContainerAutoConfiguration.Embeddedtomcat
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.tomcat (OnClassCondition)
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.apache.catalina.startup.tomcat (OnClassCondition)
- @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; SearchStrategy: current) found no beans (OnBeanCondition)
ServerPropertiesAutoConfiguration#serverProperties
- @ConditionalOnMissingBean (types: org.springframework.boot.context.embedded.properties.ServerProperties; SearchStrategy: all) found no beans (OnBeanCondition)
WebMvcAutoConfiguration
- found web application StandardServletEnvironment (OnWebApplicationCondition)
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.DispatcherServlet,org.springframework.web.servlet.config.Annotation.WebMvcConfigurerAdapter (OnClassCondition)
- found web application StandardServletEnvironment (OnWebApplicationCondition)
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.servlet.config.Annotation.WebMvcConfigurerAdapter (OnClassCondition)
- @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.Annotation.WebMvcConfigurationSupport; SearchStrategy: all) found no beans (OnBeanCondition)
WebMvcAutoConfiguration#hiddenhttpR_864_11845@ethodFilter
- @ConditionalOnMissingBean (types: org.springframework.web.filter.HiddenhttpR_864_11845@ethodFilter; SearchStrategy: all) found no beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#defaultViewResolver
- @ConditionalOnMissingBean (types: org.springframework.web.servlet.view.InternalresourceViewResolver; SearchStrategy: all) found no beans (OnBeanCondition)
Negative matches:
-----------------
RabbitAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.amqp.rabbit.core.RabbitTemplate,com.rabbitmq.client.ChAnnel (OnClassCondition)
AopAutoConfiguration
- required @ConditionalOnClass classes not found: org.aspectj.lang.Annotation.Aspect,org.aspectj.lang.reflect.Advice (OnClassCondition)
BatchAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.batch.core.launch.JobLauncher (OnClassCondition)
JpaRepositoriesAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.data.jpa.repository.JpaRepository (OnClassCondition)
MongoRepositoriesAutoConfiguration
- required @ConditionalOnClass classes not found: com.mongodb.Mongo,org.springframework.data.mongodb.repository.MongoRepository (OnClassCondition)
DatasourceAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType (OnClassCondition)
DatasourcetransactionManagerAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.jdbc.core.JdbcTemplate,org.springframework.transaction.PlatformtransactionManager (OnClassCondition)
jmstemplateAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.jms.core.jmstemplate,javax.jms.ConnectionFactory (OnClassCondition)
DeviceResolverAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.mobile.device.DeviceResolverHandlerInterceptor,org.springframework.mobile.device.DeviceHandlerMethodArgumentResolver (OnClassCondition)
HibernateJpaAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.orm.jpa.LocalContainerEntitymanagerfactorybean,org.springframework.transaction.Annotation.EnabletransactionManagement,javax.persistence.Entitymanager,org.hibernate.ejb.HibernateEntitymanager (OnClassCondition)
ReactorAutoConfiguration
- required @ConditionalOnClass classes not found: reactor.spring.context.config.EnableReactor (OnClassCondition)
ThymeleafAutoConfiguration
- required @ConditionalOnClass classes not found: org.thymeleaf.spring3.SpringTemplateENGIne (OnClassCondition)
EmbeddedServletContainerAutoConfiguration.Embeddedjetty
- required @ConditionalOnClass classes not found: org.eclipse.jetty.server.Server,org.eclipse.jetty.util.Loader (OnClassCondition)
MultipartAutoConfiguration
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
- @ConditionalOnClass classes found: javax.servlet.Servlet,org.springframework.web.multipart.support.StandardServletMultipartResolver (OnClassCondition)
- @ConditionalOnBean (types: javax.servlet.MultipartConfigElement; SearchStrategy: all) found no beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#beAnnameViewResolver
- @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)
WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter#viewResolver
- @ConditionalOnBean (types: org.springframework.web.servlet.View; SearchStrategy: all) found no beans (OnBeanCondition)
WebSocketAutoConfiguration
- required @ConditionalOnClass classes not found: org.springframework.web.socket.WebSocketHandler (OnClassCondition)
2013-11-24 00:48:44.650 INFO 15786 --- [ main] Hello.Application : Started Application in 4.125 seconds
@Configuration
@EnableAutoConfiguration
public class SampleWebStaticApplication implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("html","text/html;charset=utf-8");
factory.setMimeMappings(mappings );
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleWebStaticApplication.class,args);
}
}
如果您需要更多控制,您可以在资源处理程序级别执行某些操作.
以上是大佬教程为你收集整理的java – Spring-boot UTF-8资源全部内容,希望文章能够帮你解决java – Spring-boot UTF-8资源所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。