【发布时间】:2015-02-18 02:33:08
【问题描述】:
我遇到了一些问题。我正在使用所有基于 Java 的配置,减去 logback.xml,因为我没有找到一个很好的例子来说明如何在没有 XML 的情况下进行配置。
反正我的问题是什么时候做
mvn clean build
因为找不到 web.xml 而失败。这是一个问题,因为我使用的是 QueryDSL,它有一个 Maven 插件来生成它需要的类。所以我需要能够在没有 web.xml 的情况下进行 Maven 构建,或者我需要能够在没有 Maven 的情况下生成 QueryDSL 元类。
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>igdb</finalName>
</build>
我的 web.xml 已被此代码替换。
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
public class ApplicationInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
/**
* If no active profile is set via -Dspring.profiles.active then the application
* will default to development mode
*/
container.setInitParameter("spring.profiles.default", "dev");
/**
* create the root Spring application context
*/
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.setDisplayName("IGDb");
rootContext.register(AppConfig.class);
/**
* manage the lifecycle of the root application context
*/
container.addListener(new ContextLoaderListener(rootContext));
/**
* register and map the dispatcher servlet
*/
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
【问题讨论】:
标签: java maven querydsl spring-java-config