小编Sat*_*tya的帖子

Spring Boot uber jar打包类到root而不是BOOT-INF/classes

嗨春季启动专家 -

我正在尝试创建一个需要部署到apache风暴集群的spring boot uber jar.但是,问题在于,当使用"spring-boot-maven-plugin"打包时,Storm正在期望jar的根目录中的所有类文件,而打包的app文件在"BOOT-INF/classes"下.

有没有办法让我的应用程序类直接打包在根目录下而不是"BOOT-INF/classes"?

我尝试使用"maven-assembly-plugin"和"spring-boot-maven-plugin",如下所示,它创建了Uber jar,包含来自uber jar根目录的依赖jar中的所有类文件,但是app类仍然在BOOT-INF/classes.

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>
                    <groupId>org.apache.storm</groupId>
                    <artifactId>storm-core</artifactId>
                </exclude>
            </excludes>
            <requiresUnpack>
                <dependency>
                    <groupId>com.myorg</groupId>
                    <artifactId>my-app-artifact</artifactId> <!-- This does not help! :( -->
                </dependency>
            </requiresUnpack>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
            <appendAssemblyId>false</appendAssemblyId>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
        <executions>
            <execution>
                <id>make-assembly</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

spring maven maven-assembly-plugin spring-boot apache-storm

9
推荐指数
1
解决办法
6658
查看次数

Spring Cloud Stream和Kafka集成错误处理

我正在尝试使用Spring Cloud Stream和Kafka集成创建Spring Boot应用程序.我在Kafka中创建了一个带有1个分区的示例主题,并根据此处给出的指示从Spring Boot应用程序发布了该主题

http://docs.spring.io/spring-cloud-stream/docs/1.0.2.RELEASE/reference/htmlsingle/index.html

https://blog.codecentric.de/en/2016/04/event-driven-microservices-spring-cloud-stream/

Spring Boot App -

@SpringBootApplication
public class MyApplication {

    private static final Log logger = LogFactory.getLog(MyApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

卡夫卡制片人班

@Service
@EnableBinding(Source.class)
public class MyProducer {

    private static final Log logger = LogFactory.getLog(MyProducer.class);

    @Bean
    @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
    public MessageSource<TimeInfo> timerMessageSource() {
        TimeInfo t = new TimeInfo(new Timestamp(new Date().getTime())+"","Label");
        MessageBuilder<TimeInfo> m = MessageBuilder.withPayload(t);
        return () -> m.build();
    } …
Run Code Online (Sandbox Code Playgroud)

apache-kafka spring-cloud-stream spring-kafka

5
推荐指数
0
解决办法
978
查看次数

Spring Test Service自动装配导致null

我能够运行一个Rest Controller PUT方法,该方法通过Spring Boot Application按预期使用Autowired @Service.尝试执行Spring JUnit测试时,相同的自动装配失败.我试过阅读具有类似问题的多个线程.我确定我没有通过"new"关键字创建@Service,我尝试了Context Configuration和其他方法..但似乎都是徒劳的.我不确定我哪里出错了.

我的Spring Boot应用程序类 -

@SpringBootApplication    
@ComponentScan({    
        "com.initech.myapp.*"    
        })    
public class IngestionServerApplication {    

    private static final Log logger = LogFactory.getLog(IngestionServerApplication.class);    

    public static void main(String[] args) {    
        SpringApplication.run(IngestionServerApplication.class, args);    
        logger.info("Ingestion Server Application started...");    
    }    
}
Run Code Online (Sandbox Code Playgroud)

休息控制器类 -

package com.initech.myapp.ingestion.controller;  

@RestController  
public class IngestionController extends BaseRestController {  

    private static final Log logger = LogFactory.getLog(IngestionController.class);  

    // This variable is getting "null" autowiring if invoked 
    // via Spring Unit Testing framework while it is injected fine via
    // …
Run Code Online (Sandbox Code Playgroud)

spring spring-test-mvc spring-boot

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

AngularJS客户端,JAX-RS泽西休息服务 - 应用程序/ json客户端请求抛出'解析媒体类型时出错'

我使用下面的AngularJS客户端代码来执行带有JSON格式有效负载的HTTP post请求到jersey rest服务

patientMgmtModule.controller('NewPatientCtrl',
function NewPatientCtrl($scope, $http)
{
    $scope.addPatient = function (){

    var patientJSON = angular.toJson($scope.Patient);
    console.log("Patient (JSON) is ============> " + patientJSON);

    $http({
      method: 'POST',
      data: $scope.Patient,
      url:'/ManagePatient/AddPatient',
      headers: {'Content-Type':'application/x-www-form-urlencoded;application/json;'}
    });
};
Run Code Online (Sandbox Code Playgroud)

});

我对Jersey有以下maven依赖项:

 <dependency>
    <groupId>org.glassfish.jersey.archetypes</groupId>
    <artifactId>jersey-quickstart-webapp</artifactId>
    <version>2.0</version>
  </dependency>
  <dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet-core</artifactId>
    <version>2.0</version>
  </dependency>
Run Code Online (Sandbox Code Playgroud)

在服务器端,我有

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.hms.app.ui.beans.Patient;

@Path("/ManagePatient")
public class PatientController {

  @POST
  @Path("/AddPatient")
  @Consumes({MediaType.APPLICATION_JSON})
  public String addPatient(Patient patient) {
    System.out.println("Sarat's servlet called" );
    //patient.toConsole();
    System.out.println("Done Calling …
Run Code Online (Sandbox Code Playgroud)

jax-rs angularjs jersey-2.0

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

Spring Kafka倾听所有主题并调整分区偏移

基于spring-kafka的文档,我使用基于注释的@KafkaListener来配置我的消费者.

我看到的是 -

  1. 除非我将偏移量指定为零,否则在开始时,Kafka消费者将收集未来的消息,而不是现有的消息.(我知道这是预期的结果,因为我没有指定我想要的偏移量)

  2. 我在文档中看到一个选项,用于指定主题+分区组合以及零偏移,但如果我这样做 - 我必须明确指定我希望我的消费者听哪个主题.

使用上面的方法2,这就是我的消费者现在的样子 -

@KafkaListener(id = "{group.id}",
        topicPartitions = {
                @TopicPartition(topic = "${kafka.topic.name}",
                        partitionOffsets = @PartitionOffset(partition = "0", initialOffset = "0"))
        },
        containerFactory = "kafkaListenerContainerFactory")
public void listen(@Payload String payload,
                   Acknowledgment ack) throws InterruptedException, IOException {

    logger.debug("This is what we received in the Kafka Consumer = " + payload);

    idService.process(payload);

    ack.acknowledge();
}
Run Code Online (Sandbox Code Playgroud)

虽然我知道有一个选项可以指定"topicPattern"通配符或"主题"列表作为注释配置的一部分,但我没有看到我可以提供偏移值从零开始的地方列出的主题/主题模式.有没有办法将两者结合起来?请指教.

spring-integration apache-kafka spring-kafka

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