【发布时间】:2016-07-10 05:19:10
【问题描述】:
我在 tomcat 8 的外部 vm 中部署了 spring boot 应用程序。但是,当我尝试加载它时。我抛出 HTTP 404 (resource not available) 。下面是 catalina.out 文件的内容
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.controller.Application]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
我能做些什么来解决这个问题。我是弹簧靴的新手。请帮忙。添加application.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan(basePackages="com.abc")
@EnableJpaRepositories("com.abc.repository")
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
@PropertySource("application.properties")
@EntityScan("com.abc.pojo")
public class Application extends SpringBootServletInitializer {
@Autowired
private LdapDAO ldapDao;
@Autowired
private HoursService hoursService;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
谢谢, 普尔娜。
【问题讨论】:
-
看起来您的
application.properties文件未包含在构建中。请检查一下。 -
Application.properties 文件已经存在于 web-inf 的 classes 文件夹中。
-
发布你的课程
com.altair.dlc.controller.Application。 -
添加了代码作为问题本身的一部分。请看一下。
-
尝试将
@SpringBootApplication注释添加到您的班级。
标签: java spring spring-boot spring-data-rest tomcat8