将Java和Scala集成到一个项目中

将Java和Scala集成到一个项目中,java,scala,Java,Scala,我非常熟悉Java及其Spring框架。 所以我们使用的是SpringBoot项目,我们已经使用java实现了各种服务,现在我们想在其中添加一些scala服务(用于spark实现) 这样我就可以轻松地处理来自控制器(由UI提交)的请求 有谁能推荐一些不同的方法或最佳实践,我可以遵循它们来构建项目和创建服务吗 如果您能用一些示例或用例来解释,那将非常有帮助。我经常使用的混合Java和Scala的方法是基于Maven的。 在pom.xml中,将Scala编译器插件置于Maven编译器插件之上:

我非常熟悉Java及其Spring框架。 所以我们使用的是SpringBoot项目,我们已经使用java实现了各种服务,现在我们想在其中添加一些scala服务(用于spark实现)

这样我就可以轻松地处理来自控制器(由UI提交)的请求

有谁能推荐一些不同的方法或最佳实践,我可以遵循它们来构建项目和创建服务吗


如果您能用一些示例或用例来解释,那将非常有帮助。

我经常使用的混合Java和Scala的方法是基于Maven的。 在
pom.xml
中,将Scala编译器插件置于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>
src/main/java
net.alchim31.maven

.

可能的重复需要更多详细信息:您使用的是什么样的scala项目/框架?或者您需要推荐一款与Spring兼容的产品吗?您能否澄清您是否想要使用Spring以及您需要从中获得什么?一般来说,使用Spring的依赖注入模式可以工作,但不是scala的惯用模式