2016-12-07 80 views
0

請幫我提供文章Secure Spring REST API using OAuth2的詳細信息。Java Spring(Maven)使用OAuth2的REST API

如何從給定的source code運行SpringRestClient?

這是pom.xml,缺少什麼?

<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.websystique.springmvc</groupId> 
<artifactId>SpringSecurityOAuth2Example</artifactId> 
<version>1.0.0</version> 
<packaging>war</packaging> 

<name>SpringSecurityOAuth2Example</name> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <springframework.version>4.3.1.RELEASE</springframework.version> 
    <springsecurity.version>4.1.1.RELEASE</springsecurity.version> 
    <springsecurityoauth2.version>2.0.10.RELEASE</springsecurityoauth2.version> 
    <jackson.library>2.7.5</jackson.library> 
</properties> 

<dependencies> 
    <!-- Spring --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${springframework.version}</version> 
    </dependency> 

    <!-- Spring Security --> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-web</artifactId> 
     <version>${springsecurity.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.security</groupId> 
     <artifactId>spring-security-config</artifactId> 
     <version>${springsecurity.version}</version> 
    </dependency> 

    <!-- Spring Security OAuth2--> 
    <dependency> 
     <groupId>org.springframework.security.oauth</groupId> 
     <artifactId>spring-security-oauth2</artifactId> 
     <version>${springsecurityoauth2.version}</version> 
    </dependency> 

    <!-- Jackson libraries --> 
    <dependency> 
     <groupId>com.fasterxml.jackson.core</groupId> 
     <artifactId>jackson-databind</artifactId> 
     <version>${jackson.library}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.fasterxml.jackson.dataformat</groupId> 
     <artifactId>jackson-dataformat-xml</artifactId> 
     <version>${jackson.library}</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.1.0</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <warSourceDirectory>src/main/webapp</warSourceDirectory> 
        <warName>SpringSecurityOAuth2Example</warName> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
       </plugin> 
      </plugins> 
     <finalName>SpringSecurityOAuth2Example</finalName> 
</build> 

請注意,郵差客戶端工作正常。什麼是Maven命令來運行SpringRestClient類? SpringSecurityOAuth2Example.war是從mvn包生成的。

感謝

回答

1

考慮您pom.xml是SpringSecurityOAuth2Example文件夾內,以便從該文件夾,你可以運行下面的命令。請確保您的war文件部署在tomcat中,並且服務器正在運行,因爲SpringRestClient將在http://localhost:8080/SpringSecurityOAuth2Example處尋找服務。請在運行此命令之前重新啓動您的tomcat,否則可能會引發錯誤。

mvn -Dexec.mainClass=com.websystique.springmvc.SpringRestClient -Dexec.classpathScope=test test-compile exec:java 
+0

謝謝你的回答。 – Impavid