zl程序教程

您现在的位置是:首页 >  后端

当前栏目

springboot+thymeleaf打war包在外部tomcat运行详解编程语言

SpringBootTomcat编程语言 详解 运行 外部 war thymeleaf
2023-06-13 09:20:45 时间
工程目录 springboot+thymeleaf打war包在外部tomcat运行详解编程语言

 

pom文件注意点
 packaging war /packaging 

groupId org.springframework.boot /groupId artifactId spring-boot-starter-tomcat /artifactId scope provided /scope /dependency
groupId org.apache.maven.plugins /groupId artifactId maven-compiler-plugin /artifactId /plugin /plugins /build 配置文件application.properties
server.port=8013 

server.session.timeout=3000 

server.context-path=/prs 

#thymelea模板配置 

spring.thymeleaf.prefix=classpath:/templates/ 

spring.thymeleaf.suffix=.html 

spring.thymeleaf.mode=HTML5 

spring.thymeleaf.encoding=UTF-8 

spring.thymeleaf.content-type=text/html 

spring.thymeleaf.cache=false 

#spring.resources.chain.strategy.content.enabled=true 

#spring.resources.chain.strategy.content.paths=/** 

# 上传文件大小配置 

spring.http.multipart.maxFileSize=10MB 

spring.http.multipart.maxRequestSize=10MB 

#spring.mvc.async.request-timeout=600000 

#spring.http.multipart.max-request-size=200MB 

#spring.aop.auto=true 

#spring.aop.proxy-target- >

server.context-path=/prs这里的路径名最好和上面pom里的finalName最好是一致的,因为当我们把打包好的war包放到tomcat的webapp里时,访问路径前缀就是这个finalName
@ComponentScan(basePackages= {"com.wymessi"})//扫描组件 

@SpringBootApplication 

@EnableAspectJAutoProxy 

@EnableTransactionManagement(proxyTargetClass = true) 

@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class}) 

public class SpringbootApplication extends SpringBootServletInitializer { 

 public static void main(String[] args) { 

 SpringApplication.run(SpringbootApplication.class, args); 

 @Override 

 protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 

 // 注意这里要指向原先用main方法执行的Application启动类 

 return builder.sources(SpringbootApplication.class); 

// @Bean 

// public HttpMessageConverters fastJsonHttpMessageConverters() { 

// FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); 

// FastJsonConfig fastJsonConfig = new FastJsonConfig(); 

// // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserCompatible); 

// // fastJsonConfig.setSerializerFeatures(SerializerFeature.BrowserSecure); 

// fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); 

// // fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue); 

// SerializeConfig config = new SerializeConfig(); 

// config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss")); 

// fastJsonConfig.setSerializeConfig(config); 

// fastConverter.setFastJsonConfig(fastJsonConfig); 

// HttpMessageConverter ? converter = fastConverter; 

// return new HttpMessageConverters(converter); 

// } 

}

和打jar包的区别是继承了SpringBootServletInitializer这个类,然后重写了configure方法。

eclipse里运行

右击项目名,run as spring boot app。

浏览器里输入http://127.0.0.1:8013/prs

打包成war包在tomcat里运行

右击项目名,run as maven build,看到success就代表打包成功了。

springboot+thymeleaf打war包在外部tomcat运行详解编程语言

把打包好的prs放到tomcat的webapp里,然后启动tomcat。

这里要注意,tomcat的访问端口要设置成和配置文件里的一样,不然用配置文件里的port是访问不到的。

打包的名称要和server.context-path=/prs的名称一致,不然也是访问不到的,这个上面已经说过了。

浏览器里输入http://127.0.0.1:8013/prs

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/15686.html

cjavamysqlsqlserverxml