2016-12-07 56 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