2017-04-27 6 views
1

私はthis反応と春のブートを使用してWebアプリケーションを作成するためのチュートリアルに従った。反応とリンクスプリングブート

私はまったく同じ手順に従っていましたが、私の反応アプリではwebpackを導入しました。反応アプリが起動しています。

pom.xmlファイルは、次のようになります。

<?xml version="1.0" encoding="UTF-8"?> 

http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0

<groupId>com.example</groupId> 
<artifactId>ema</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

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

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.5.3.RELEASE</version> 
    <relativePath/> <!-- lookup parent from repository --> 
</parent> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

<build> 
<plugins> 
    <plugin> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-maven-plugin</artifactId> 
    </plugin> 


    <plugin> 
    <groupId>com.github.eirslett</groupId> 
    <artifactId>frontend-maven-plugin</artifactId> 
    <version>1.2</version> 
    </plugin> 

    <plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>3.0.2</version> 
    <executions> 
    <execution> 
    <id>Copy frontend production build to resources</id> 
    <phase>package</phase> 
    <goals> 
    <goal>copy-resources</goal> 
    </goals> 
    <configuration> 
    <outputDirectory>${basedir}/target/classes</outputDirectory> 
    <resources> 
    <resource> 
    <directory>src/main/app/build/</directory> 
    <filtering>true</filtering> 
    </resource> 
    </resources> 
    </configuration> 
    </execution> 
    </executions> 
    </plugin> 


    </plugins> 
</build> 

私はチュートリアルの最後の段階になった:

mvn clean package 
java -jar target/cra-demo-0.0.1-SNAPSHOT.jar 

しかし、私は私の春のサーバがclosigであることを参照してください。

:: Spring Boot ::  (v1.5.3.RELEASE) 

2017-04-27 15:01:33.740 INFO 28295 --- [   main] com.example.EmaApplication    : Starting EmaApplication v0.0.1-SNAPSHOT on robucslvm03 with PID 28295 (/home/gecobici/EMA/target/ema-0.0.1-SNAPSHOT.jar started by gecobici in /home/gecobici/EMA) 
2017-04-27 15:01:33.748 INFO 28295 --- [   main] com.example.EmaApplication    : No active profile set, falling back to default profiles: default 
2017-04-27 15:01:33.860 INFO 28295 --- [   main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]255316f2: startup date [Thu Apr 27 15:01:33 EEST 2017]; root of context hierarchy 
2017-04-27 15:01:34.936 INFO 28295 --- [   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 
2017-04-27 15:01:34.958 INFO 28295 --- [   main] com.example.EmaApplication    : Started EmaApplication in 2.06 seconds (JVM running for 2.877) 
2017-04-27 15:01:34.958 INFO 28295 --- [  Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]255316f2: startup date [Thu Apr 27 15:01:33 EEST 2017]; root of context hierarchy 
2017-04-27 15:01:34.959 INFO 28295 --- [  Thread-2] o.s.j.e.a.AnnotationMBeanExporter  : Unregistering JMX-exposed beans on shutdown 

私は春のサーバーの起動および実行を取得し、私のアプリを反応させると対話する方法がわからない、春に新しいですし、反応します。

編集:私は持っているのpom.xmlで :

<directory>src/main/app/build/</directory> 

私はWebPACKの-pと生産ビルドを作成するが、私は何のビルドフォルダを参照してくださいません。 ビルドフォルダにプロダクションビルドを生成するにはどうすればよいですか?

答えて

0

導入したwebpackの魔法はまったく悪くない、春のReactアプリケーションの使用を簡略化するために、Webpack Proxyを設定して特定のポートのすべてのHTTP要求を傍受することができます。 :あなたは次のことを許可する必要があなたの春のアプリで

'webpack-dev-server': { 
     options: { 
     webpack: webpackConfig, 
     inline: true, 
     }, 
     start: { 
     host: '0.0.0.0', 
     port: '<%= config.webpackDevServerPort %>', 
     contentBase: '<%= config.dist %>', 
     webpack: { 
      devtool: 'inline-source-map', 
      debug: true, 
     }, 
     proxy: { 
      '/myapp': { 
      target: 'http://localhost:' + (grunt.option('proxy-port') || config.connectPort), 
      secure: false, 
      }, 
     }, 
     }, 
    }, 

最後の一つです:

/** 
    * Register WebSocket publisher 
    * 
    * @param registry where the handler will be registered 
    */ 
    @Override 
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 
    registry.addHandler(publisher, webSocketPath).setAllowedOrigins("*"); 
    } 

外側スプリングサーバーが傍受されることはありませんから、あなたがsetAllowedOrigins("*");残り呼び出していない場合、これはただのためにありますデベロッパーとアプリケーションgを無効にする必要があります生産に至りました。

+0

webpackを使用してビルドフォルダにプロダクションビルドを作成するにはどうすればよいですか? –

+0

webpack configにプロキシ設定を追加して同じ動作をしました –

+0

webpackはあなたのアプリを壊してしまい、mavenを使用してフロントとバックを1つのjarファイルにパッケージ化して実行する必要があります –

関連する問題