We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
公司给客户定制的项目,需求是:
<?xml version="1.0" encoding="UTF-8"?> <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> ... <packaging>war</packaging> ... <dependencies> ... <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> ... </dependencies> <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>application.properties</exclude> </excludes> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.Application</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <showWarnings>true</showWarnings> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> </project>
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.ComponentScan; import java.util.Properties; @SpringBootApplication @ComponentScan // 开启通用注解扫描 @ServletComponentScan // 扫描使用注解方式的servlet public class Application extends SpringBootServletInitializer implements EmbeddedServletContainerCustomizer { private static Logger logger = LoggerFactory.getLogger(Application.class); @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(Application.class) .properties(getProperties()); } public static void main(String[] args) { ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(Application.class) .properties(getProperties()) .build().run(args); } /** * 设置配置文件 * @return */ private static Properties getProperties() { Properties props = new Properties(); props.put("spring.config.location", "/path/to/application.properties"); return props; }
直接maven编译项目,放入tomcat的webapps目录下即可
The text was updated successfully, but these errors were encountered:
No branches or pull requests
场景
公司给客户定制的项目,需求是:
解决步骤
1、pom文件修改
2、 修改主启动类的配置方法:
3、启动项目
直接maven编译项目,放入tomcat的webapps目录下即可
The text was updated successfully, but these errors were encountered: