1. 程式人生 > >Springboot+Axis1.4+Mybatis(oracle)+前端html 整合釋出

Springboot+Axis1.4+Mybatis(oracle)+前端html 整合釋出

最近商務經常要求我出差去給客戶做演示,每次推諉商務都已自己不會部署為理由,一怒之下產生了做這件事情的想法.

首先附上pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>

	<name>demo</name>
	<description>Demo project for Spring Boot</description>

	<properties>
		<java.version>1.8</java.version>
	</properties>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.1.RELEASE</version>
	</parent>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<!-- druid資料庫連線池 -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.0.26</version>
		</dependency>
		<!-- springboot的mybatis -->
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!-- MySql資料庫驅動 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<!-- Springboot 熱部署 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

		<dependency>
			<groupId>ojdbc</groupId>
			<artifactId>ojdbc5</artifactId>
			<version>0.0.1-SNAPSHOT</version>
		</dependency>
		
		
		<!-- axis 1.4 jar start -->
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-saaj</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>
        <!-- axis 1.4 jar end -->

	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<!--這裡寫上main方法所在類的路徑 -->
				<configuration>
					<mainClass>cn.biceng.App</mainClass>
				</configuration>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

本人開發工具用的MyEclipse2017

下面是目錄結構,供大家參考

application.yml 檔案:

    主要是設定埠號,資料庫地址,還有html模板

由於相關的jar包已經匯入,所以我們直接開始愉快的編碼了.

首先是啟動類:

package cn.biceng;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;


@SpringBootApplication  
public class App extends SpringBootServletInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(App.class);
    }
	
    public static void main(String[] args) throws Exception {
    	SpringApplication application=new SpringApplication(App.class);
    	application.run(args);
    }
}

dao層:

package cn.biceng.dao;

import org.apache.ibatis.annotations.Select;

public interface SealMapper {
	
	@Select("select login from users where id=#{id}")
	String select(String id);
}

controller層:

package cn.biceng.controller;

import java.util.Map;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.biceng.dao.SealMapper;
@Controller
@EnableAutoConfiguration
@MapperScan("cn.biceng.dao")
public class SealMessageControl {

	@Autowired
	private SealMapper sealMapper;

    @RequestMapping("/")
    @ResponseBody
    String home() {
    	String s=sealMapper.select("7003");
    	System.out.println(s);
        return "哪裡需要簽名蓋章,哪裡就有百潤百成";
    }
    
    @RequestMapping("/index")
    public String toIndex(Map<String, Object> model) {
       
    	//return "thymeleaf/index";
    	return "MyHtml";
    }
}

至此簡單的springboot+mybatis框架就整合完成了

測試一波 右鍵main方法執行


隨後我們把前端頁面也整合進來:

首先在resource目錄下建立如下的結構,static下放 js,css,image的資原始檔

templates下面放html模板對應著application.yml的內容

然後隨便去菜鳥教程上面找一個demo複製下來

部署啟動:

後面的操作就是MVC標準操作了,此處不多涉及.

然後我們整合axis.

首先jar包在pom.xml中已經匯入,先準備一個wsdd檔案.放在WEB-INF下面

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
	xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
	<!-- globalConfiguration 標籤內容為系統預設 無需更改 -->
	<globalConfiguration>
		<parameter name="adminPassword" value="admin" />
		<parameter name="attachments.Directory" value="./attachments" />
		<parameter name="attachments.implementation"
			value="org.apache.axis.attachments.AttachmentsImpl" />
		<parameter name="sendXsiTypes" value="true" />
		<parameter name="sendMultiRefs" value="true" />
		<parameter name="sendXMLDeclaration" value="true" />
		<parameter name="axis.sendMinimizedElements" value="true" />
		<requestFlow>
			<handler type="java:org.apache.axis.handlers.JWSHandler">
				<parameter name="scope" value="session" />
			</handler>
			<handler type="java:org.apache.axis.handlers.JWSHandler">
				<parameter name="scope" value="request" />
				<parameter name="extension" value=".jwr" />
			</handler>
		</requestFlow>
	</globalConfiguration>
	<handler name="LocalResponder"
		type="java:org.apache.axis.transport.local.LocalResponder" />
	<handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
	<handler name="Authenticate"
		type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" />
	<!--service 標籤是需要配置的 -->
	<!-- name 是url中需要的引數 -->
	<service name="htmlService" provider="java:RPC">
		<!-- allowedMethods 的value值是方法名 可以寫 -->
		<parameter name="allowedMethods" value="*" />
		<!--className的value值是類路徑 -->
		<parameter name="className" value="cn.biceng.Axisaction" />
		<!--wsdlTargetNamespace的wsdl檔案中TargetNamespace的值 -->
		<parameter name="wsdlTargetNamespace"
			value="http://axis.biceng.cn" />
		<!--此處很重要,若方法需要傳實體類,則配置此處 -->
		<!-- <beanMapping qname="myNS:User" xmlns:myNS="urn:BeanService"
			languageSpecificType="java:cn.biceng.User" /> -->
	</service>
	<!--預設 -->
	<transport name="http">
		<requestFlow>
			<handler type="URLMapper" />
			<handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
		</requestFlow>
	</transport>
	<transport name="local">
		<responseFlow>
			<handler type="LocalResponder" />
		</responseFlow>
	</transport>
</deployment>

然後對應寫你需要釋出的方法

package cn.biceng;

public class Axisaction {
	
	public void test(){
		System.out.println("12312312");
	}
}

然後執行

大工搞成! 然後就是打包了,由於jar包不包含wabapp的內容,所以我們打成war包釋出.

注意此處的

隨後run configurations

一鍵搞定.

不報錯的情況下我們就能在target目錄下看到我們的war包

找到這個war包的位置

開啟CMD.確認有java

然後CD到該目錄

java -jar demo-0.0.1-SNAPSHOT.war

一個重重的回車.