小编aba*_*hel的帖子

如何在spring boot中为应用程序yml定义复杂列表?

假设我有这个application.yml定义:

spring:
    profiles.active: development
---
spring:
    profiles: development
logging:
    level:
        org.springframework.web: DEBUG
        org.hibernate: ERROR
storage:
    RemoteStorage:
        name: "Server 1"
        user: "test"
        passwd: "test"
        host: "163.218.233.106"

    LocalStorage:
        name: "Server 2"
        user: "test2"
        passwd: "test2"
        host: "10.10.0.133"
---
Run Code Online (Sandbox Code Playgroud)

storage是一个自定义属性,我希望它像这样加载:

@Value("${storage}")
private List<Storage> AvailableStorage = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

抱歉,我是 Spring 框架的初学者。我试图做的是RestController根据请求提供的参数读取相应的配置,即类似的请求?storage=RemoteStorage将使用RemoteStorage配置。

java spring yaml spring-mvc spring-boot

5
推荐指数
1
解决办法
6367
查看次数

如何使用Spark在数据框中创建架构数组

我有创建数据框的代码,如果我的输入数据中没有数组,则可以正常工作。

我尝试使用没有数组的Json数据,它成功运行。我的代码是

val vals = sc.parallelize(
  """{"id":"1","name":"alex"}""" ::
  Nil
)

val schema = (new StructType)
      .add("id", StringType)
      .add("name", StringType)


  sqlContext.read.schema(schema).json(vals).select($"*").printSchema()
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我有如下所示的数组输入数据,那么如何创建模式?

     val vals = sc.parallelize(
  """{"id":"1","name":"alex","score":[{"keyword":"read","point":10}]}""" ::
  Nil
)


val schema = (new StructType)
      .add("id", StringType)
      .add("name", StringType)
Run Code Online (Sandbox Code Playgroud)

谢谢。

scala apache-spark

5
推荐指数
1
解决办法
1万
查看次数

GroupByKey并创建值列表pyspark sql dataframe

所以我有一个火花数据框,看起来像:

a | b | c
5 | 2 | 1
5 | 4 | 3
2 | 4 | 2
2 | 3 | 7
Run Code Online (Sandbox Code Playgroud)

我希望按列a分组,从列b创建值列表,并忘记c.输出数据框将是:

a | b_list
5 | (2,4)
2 | (4,3)
Run Code Online (Sandbox Code Playgroud)

我将如何使用pyspark sql数据框执行此操作?

谢谢!:)

group-by apache-spark spark-dataframe pyspark-sql

5
推荐指数
1
解决办法
3846
查看次数

如何在Spark Java中遍历/迭代数据集?

我试图遍历数据集来进行一些字符串相似度计算,如Jaro winkler或Cosine Similarity.我将我的数据集转换为行列表,然后遍历for语句,这不是有效的火花方式.所以我期待在Spark中采用更好的方法.

public class sample {

    public static void main(String[] args) {
        JavaSparkContext sc = new JavaSparkContext(new SparkConf().setAppName("Example").setMaster("local[*]"));
        SQLContext sqlContext = new SQLContext(sc);
        SparkSession spark = SparkSession.builder().appName("JavaTokenizerExample").getOrCreate();

        List<Row> data = Arrays.asList(RowFactory.create("Mysore","Mysuru"),
                RowFactory.create("Name","FirstName"));
        StructType schema = new StructType(
                new StructField[] { new StructField("Word1", DataTypes.StringType, true, Metadata.empty()),
                        new StructField("Word2", DataTypes.StringType, true, Metadata.empty()) });

        Dataset<Row> oldDF = spark.createDataFrame(data, schema);
        oldDF.show();
        List<Row> rowslist = oldDF.collectAsList(); 
    }
}
Run Code Online (Sandbox Code Playgroud)

我发现了许多我不清楚的JavaRDD示例.数据集的示例将对我有所帮助.

java iterator apache-spark apache-spark-dataset apache-spark-2.0

5
推荐指数
1
解决办法
2万
查看次数

如何将Dataset转换为JavaPairRDD?

有一些方法可以将数据集转换为JavaRDD.

Dataset<Row> dataFrame;
JavaRDD<String> data = dataFrame.toJavaRDD();
Run Code Online (Sandbox Code Playgroud)

有没有其他方法可以将数据集转换为javaPairRDD<Long, Vector>

java apache-spark apache-spark-dataset java-pair-rdd

5
推荐指数
1
解决办法
4030
查看次数

Spring Thymeleaf TemplateResolver错误

我试图在春天使用百里香叶来定位文本字符串.我的html模板位于/ src/main/resources/templates /

所以我有:

@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {

    public MvcConfig() {
        super();
    }

    @Override
    public void addViewControllers(final ViewControllerRegistry registry)             {
        super.addViewControllers(registry);
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/sorting").setViewName("sorting");
    }

    @Override
    public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/","/resource/*");
        registry.addResourceHandler("/assets/**")
    .addResourceLocations("classpath:/assets/");
        registry.addResourceHandler("/css/**")
    .addResourceLocations("/css/");
    }


    @Bean
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
        templateResolver.setCacheable(false);
        templateResolver.setPrefix("classpath:/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode("HTML5");
        return templateResolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setTemplateResolver(templateResolver());
        return …
Run Code Online (Sandbox Code Playgroud)

java spring template-engine spring-mvc thymeleaf

4
推荐指数
1
解决办法
6857
查看次数

Spark:RDD.map/mapToPair如何与Java一起使用

我有一些对CW(整数I,串词)数的出现次数的单词在文本文件中.

我想简单地为每对配对一个带有1个固定数字的新对c1(整数i,1).

这似乎是微不足道的,但我还没有理解map/mapToPair函数实际上是如何工作的.

JavaPairRDD<Integer, Integer> c1 = cw.map(??? -> new Tuple2<Integer, Integer>(??, 1));
Run Code Online (Sandbox Code Playgroud)

我正在使用Java-8.

java tuples keyvaluepair apache-spark rdd

4
推荐指数
1
解决办法
1万
查看次数

尝试从jar文件运行时,Spring Boot应用程序将无法运行

我有一个Spring Boot应用程序,当通过intellij运行时可以正常工作。但是,当我从罐子中运行它时,出现以下异常。

        2017-02-13 05:18:28.596  WARN 8581 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    2017-02-13 05:18:28.606 ERROR 8581 --- [           main] o.s.boot.SpringApplication               : Application startup failed

    org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.6.RELEASE.jar!/:4.3.6.RELEASE]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar!/:1.5.1.RELEASE] …
Run Code Online (Sandbox Code Playgroud)

java spring jar maven spring-boot

4
推荐指数
2
解决办法
7824
查看次数

Spark在UDF Java中从WrappedArray&lt;WrappedArray&lt;Double&gt;&gt;获取值

我的一列Dataset<Row> 包含WrappedArray<WrappedArray<Double>>. 我将此列传递给 anUDF以提取其中一个值。

我将如何访问这个嵌套结构中的双打?

我想做这样的事情:

sparkSession.udf().register(ADD_START_TOTAL, (UDF1<WrappedArray<WrappedArray<Double>>, Double>) (totals) -> totals[0][1], DataTypes.DoubleType);
Run Code Online (Sandbox Code Playgroud)

这是我调用Dataset.show()方法时列的示例,我的数据集如下所示。

[WrappedArray(2.0...
Run Code Online (Sandbox Code Playgroud)

编辑:在 spark (scala) 中找到了这篇文章How to cast a WrappedArray[WrappedArray[Float]] to Array[Array[Float]] 但不确定如何将其转换为 Java。

java user-defined-functions apache-spark apache-spark-sql

4
推荐指数
1
解决办法
1976
查看次数

javax.persistence.TransactionRequiredException: 没有 EntityManager 与当前线程可用的实际事务

我使用 Hibernate 创建了我的第一个 Spring MVC 项目。我的 DAO 层使用 JPA EntityManager 与数据库进行交互。

GenericDao.java:

@Repository
public abstract class GenericDao<T> implements GeneralDao<T> {

    private Class<T> className;

    public GenericDao(Class<T> className) {
        this.className = className;
    }

    @PersistenceContext
    private EntityManager entityManager;

    public EntityManager getEntityManager() {
        return entityManager;
    }

    @Override
    public void add(T object) {
        try {
            getEntityManager().persist(object);
        } catch (HibernateException e) {
            throw new DaoException(ErrorMessage.ADD_ENTITY_FAIL, e);
        }
    }

    @Override
    public void update(T object) {
        try {
            getEntityManager().merge(object);
        } catch (HibernateException e) {
            throw new DaoException(ErrorMessage.UPDATE_ENTITY_FAIL, e); …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jpa spring-mvc

3
推荐指数
2
解决办法
2万
查看次数