我没有在真实世界的网络项目上工作.在大学时,我们使用Servlet和Spring进行Java Web开发.在这两个项目中,我们都获得了已配置的web.xml文件,我们只对它们进行了微小的更改.现在我需要从头开始构建一个Web应用程序.我在Eclipse中创建了新的Servlet类,并没有自动创建任何web.xml.然后我用谷歌搜索,我从几个资源中读到了不需要web.xml,但是这个推理被放在几个句子中,所以我不确定使用注释而不是web.xml是没有问题的.如果不需要配置web.xml,我会很高兴,因为我没有自己配置,我想更多地关注业务逻辑.
先感谢您!
我试图将弹簧启动应用程序打包为战争.根据这个,我修改了应用程序类:
@SpringBootApplication
@EntityScan({"org.mdacc.rists.cghub.model"})
@EnableJpaRepositories(basePackages = {"org.mdacc.rists.cghub.ws.repository"})
public class Application extends SpringBootServletInitializer
{
public static void main( String[] args )
{
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Run Code Online (Sandbox Code Playgroud)
还在我的pom.xml中添加了以下内容
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当我打包项目时,我收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project cg-web: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
当我阅读spring boot应用程序时,我从未见过有关创建web.xml的任何内容.将Spring启动应用程序部署为战争需要web.xml吗?