我有两个项目 - 一个名为core,另一个名为ui。在核心项目中,有一个Spring Boot
应用程序启动器(Tomcat)。在ui项目中,有一个AngularJS
Web应用程序(Eclipse中的静态Web项目)。我正在使用Run -> Run As -> Java Application
运行Web应用程序,我希望Eclipse将ui项目的内容设置为核心项目的类路径或其他地方,以便Spring Boot为其提供服务。试图在运行配置中将ui项目的文件夹添加到类路径中 - 没有帮助。
结构是:
SampleWebStaticApplication.java
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleWebStaticApplication extends SpringBootServletInitializer {
private final Logger log = LoggerFactory.getLogger(SampleWebStaticApplication.class);
@Autowired
private Environment env;
@PostConstruct
public void initApplication() throws IOException {
if (env.getActiveProfiles().length == 0) {
log.warn("No Spring profile configured, running with default configuration");
} else {
log.info("Running with Spring profile(s) : {}", Arrays.toString(env.getActiveProfiles()));
}
}
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(SampleWebStaticApplication.class);
app.setShowBanner(false);
// init
app.run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.showBanner(false).sources(SampleWebStaticApplication.class);
}
}
WebConfiguration.java
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter implements ServletContextInitializer {
private final Logger log = LoggerFactory.getLogger(WebConfiguration.class);
@Autowired
private Environment env;
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
log.info("Web application configuration, using profiles: {}", Arrays.toString(env.getActiveProfiles()));
// init
log.info("Web application fully configured");
}
}
核心项目构建路径:
同样Spring Boot
应用程序不使用我的application.yml
(例如,我无法更改Tomcat的端口)。提前谢谢。
P.S。不能使用Maven :(