小编yer*_*lin的帖子

从Bash脚本中启动Spring Boot作为前台进程

我使用嵌入式Tomcat servlet容器打包Spring Boot war.并使用它将其部署为常规Java应用程序java -jar server.war <Spring Args>.我编写了一个bash脚本,负责将服务器部署为后台/前台进程:

start_foreground() {
    cmd="$JAVACMD ${JVM_OPTS} -jar ${WAR_FILE} ${SPRING_OPTS}"
    echo "\"${cmd}\""
    eval ${cmd}
    print_log "Server is stopped."
}

start_background() {
    SPRING_OPTS="--spring.pid.file=${PID_FILE} ${SPRING_OPTS}"
    cmd="nohup $JAVACMD ${JVM_OPTS} -jar ${WAR_FILE} ${SPRING_OPTS} &>${LOG_PATH}/console.log &"
    echo "\"${cmd}\""
    eval ${cmd}
    PID=$!
    print_log "Server is started with pid \"${PID}\""
}
Run Code Online (Sandbox Code Playgroud)

如您所见,对于后台进程启动我使用nohup.一切工作正常,它发送STDOUTSTDERR给我的${LOG_PATH}/console.log.console.log报告我的服务器在预配置端口上启动并运行(使用Spring配置文件).我有一个dev-https配置端口的配置文件8443:

spring:
  profiles.active: dev-https
...
---

spring:
    profiles: dev-https
server:
  port: 8443
  ssl:
    enabled: true …
Run Code Online (Sandbox Code Playgroud)

java bash spring war

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

响应没有“内容长度”标头时的 AVURLAsset

我的 iOS 应用程序使用 AVPlayer 从我的服务器播放流音频并将其存储在设备上。我实现了 AVAssetResourceLoaderDelegate,所以我可以拦截流。我改变了我的方案(从http一个假方案,这样 AVAssetResourceLoaderDelegate 方法被调用:

func resourceLoader(_ resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool

我跟着这个教程:

http://blog.jaredsinclair.com/post/149892449150/implementing-avassetresourceloaderdelegate-a

在那里,我将原始方案放回原处,并创建一个会话以从服务器提取音频。当我的服务器为Content-Length流式音频文件提供(以字节为单位的音频文件大小)标头时,一切正常。

但有时我会在无法提前提供长度的情况下流式传输音频文件(比如直播播客流)。在这种情况下,AVURLAsset 将长度设置为-1并失败:

"Error Domain=AVFoundationErrorDomain Code=-11849 \"Operation Stopped\" UserInfo={NSUnderlyingError=0x61800004abc0 {Error Domain=NSOSStatusErrorDomain Code=-12873 \"(null)\"}, NSLocalizedFailureReason=This media may be damaged., NSLocalizedDescription=Operation Stopped}"

我无法绕过这个错误。我试图采取一种骇人听闻的方式,提供 fake Content-Length: 999999999,但在这种情况下,一旦下载了整个音频流,我的会话就会失败:

Loaded so far: 10349852 out of 99999999 The request timed out. //Audio file got downloaded, its size is 10349852 //AVPlayer tries to get the next chunk and then fails with …

audio streaming ios avplayer avurlasset

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

Spring框架:ContextRefreshedEvent被多次触发

在某些情况下,例如在 Spring 应用程序上启用绑定@EnableBindingContextRefreshedEvent会开始多次被解雇。

例如,

public interface MessageBinding {
    @Input("test")
    KStream<Long, String> messagesIn();
}

@EnableBinding(MessageBinding.class)
@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Component
    public static class ComponentX {

        @Autowired
        ApplicationContext applicationContext;

        @EventListener
        public void onApplicationEvent(ContextRefreshedEvent event) {
            System.out.println("Fired event");
        }
    }
Run Code Online (Sandbox Code Playgroud)

如果删除@EnableBinding注释,ContextRefreshedEvent则只会被触发一次。

如果添加它,该事件将被触发 5 次。

spring spring-boot

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

标签 统计

spring ×2

audio ×1

avplayer ×1

avurlasset ×1

bash ×1

ios ×1

java ×1

spring-boot ×1

streaming ×1

war ×1