該工程最初版本來自于Mybatis所在的google code站點,屬于輕量級J2EE技術架構應用範圍,使用了Spring、Stripes和MyBatis開源架構。其中Stripes為MVC架構的一種,該架構的設計和使用理念是零配置。熟悉該工程後主要是做了兩方面的改進,一個是開發調試方面,另一個是資料庫連接配接方面。
本文主要介紹開發調試方面:采用Jetty Web Server進行開發調試,效率更高。
方式1:maven指令行方式
該方式比較簡單,隻需在工程的pom檔案裡添加一個插件,其具體内容如下:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>3</scanIntervalSeconds>
<scanTargetPatterns>
<scanTargetPattern>
<directory>src/main/webapp/WEB-INF</directory>
<excludes>
<exclude>***.properties</include>
<include>**
public static void main(String[] args) {
new PetStoreJettyServer();
}
// Jetty 6
public PetStoreJettyServer() {
//LOG.info("Starting web...");
try {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});
String[] tryPaths = new String[] {
"mybatis-jpetstore/src/main/webapp",
"../mybatis-jpetstore/src/main/webapp"
};
String webapp = System.getProperty("webapp");
if (webapp == null) {
for (String tryPath : tryPaths) {
if (new File(tryPath).exists()) {
webapp = tryPath;
}
}
}
if (webapp == null) {
//LOG.severe("Could not find suitable web app sources to deploy, failing");
return;
}
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/");
webappcontext.setWar(webapp);
HandlerCollection handlers= new HandlerCollection();
handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()});
server.setHandler(handlers);
server.start();
try {
server.join();
} catch (InterruptedException e) {
//LOG.severe(e);
}
} catch (Exception e) {
//LOG.severe(e);
}
}
}
轉載于:https://blog.51cto.com/minglu/920675