2013-02-28 40 views
1

我在想如何在Spring MVC應用程序中實現視頻功能。我需要使用其他技術,比如jQuery,還是Spring支持視頻功能?在Spring MVC中實現視頻

+0

視頻是資源,就像圖片或CSS文件一樣。無論你使用Spring MVC還是其他任何東西都是相關的。如果你想要的是流媒體,那麼這是另一回事。請說明你確實想要做什麼。 – 2013-02-28 21:43:36

回答

0

Spring Content支持開箱即用的視頻流(字節範圍)。它支持各種後備存儲。使用Spring Content FS(即文件系統的Spring內容),您可以創建自己的「視頻存儲」,由它通過HTTP存儲到客戶端的文件系統和流式視頻支持。

通過start.spring.io或通過IDE彈簧工程嚮導(Spring Boot 1.5.10)創建一個新的Spring Boot項目。所以你最終這些添加下列啓動春/內容相關性: -

<dependencies> 
    <!-- Spring Boot --> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.3</version> 
    </dependency> 

    <!-- Spring Content --> 
    <dependency> 
     <groupId>com.github.paulcwarren</groupId> 
     <artifactId>spring-content-fs-boot-starter</artifactId> 
     <version>0.0.9</version> 
    </dependency> 
    <dependency> 
     <groupId>com.github.paulcwarren</groupId> 
     <artifactId>spring-content-rest-boot-starter</artifactId> 
     <version>0.0.9</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

然後在你的春天引導應用程序類,創建一個VideoStore。將其註釋爲StoreRestResource。這有兩件事。它會導致春季項目注入此接口的實現(文件系統),以及注射REST端點在這個界面的頂部太 - 不必任何本自己寫節省您: -

@SpringBootApplication 
    public class DemoApplication { 

     public static void main(String[] args) {   
      SpringApplication.run(DemoApplication.class, args); 
     } 

     @StoreRestResource(path="videos") 
     public interface VideoStore extends Store<String> {} 
    } 

默認Spring內容(用於文件系統)將在java.io.tmpdir下創建一個存儲。因此,您還需要設置SPRING_CONTENT_FS_FILESYSTEM_ROOT環境變量或系統屬性以爲「商店」設置穩定的根位置,以便在應用程序/服務重新啓動時可以再次找到該視頻。

將您的視頻複製到此「根」位置。啓動應用程序和視頻(S)將是流化: -

/videos/some-video.mp4

春天內容支持其他存儲太多;目前是S3,Mongo的GridFS和JPA(即BLOB)。

它也可以在沒有Spring Boot的情況下使用。如果這個選擇是有趣的讓我知道,我可以爲你更新答案。