我有一个正在运行的Spring Web项目(A)与外部Tomcat,现在,我想转移到Spring云,需要支持(A),当我作为Spring引导Web项目与外部Tomcat运行时, applicationContext.xml加载两次。
代码如下:
package com.pa.openapi.gateway.core;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@EnableWebMvc
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class })
@EnableDiscoveryClient
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
System.out.println("*********************Application***************************************");
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
package com.pa.openapi.gateway.core;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource("classpath*:applicationContext.xml")
public class ConfigurationClass { }
Tomcat as apache-tomcat-8.0.24
如果您有任何疑问,请告诉我。