我对Java及其Spring框架非常熟悉。 因此,我们正在使用spring boot项目,其中我们已经使用java实现了各种服务,现在我们想在其中添加一些scala服务(用于spark实现)。
这样我就可以轻松处理来自控制器(由UI提交)的请求。
任何人都可以提出一些我可以遵循的不同方法或最佳实践来构建项目和创建服务
如果您可以通过一些示例或用例进行说明,那将是非常有用的帮助。
答案 0 :(得分:1)
我经常将Java和Scala混合使用的方法是基于Maven的。
将Scala编译器插件放在pom.xml
中Maven编译器插件的上方:
<sourceDirectory>src/main/java</sourceDirectory>
<!--<testSourceDirectory>src/test/scala</testSourceDirectory>-->
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.4.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<configuration>
<recompileMode>incremental</recompileMode>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
<configuration>
<args>
<arg>-Ydelambdafy:method</arg>
<arg>-target:jvm-1.8</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-unchecked</arg>
<arg>-language:implicitConversions</arg>
<arg>-language:postfixOps</arg>
</args>
</configuration>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-Ydelambdafy:method</arg>
<arg>-target:jvm-1.8</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-unchecked</arg>
<arg>-language:implicitConversions</arg>
<arg>-language:postfixOps</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<compilerId>javac</compilerId>
<debug>true</debug>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>