我正在尝试通过Spring webSocket在客户端和服务器之间建立连接,我正在通过此链接进行此操作.我希望Controller每隔5秒向客户端发送一个"hello",客户端每次都会将它附加到问候语框中.这是控制器类:
@EnableScheduling
@Controller
public class GreetingController {
@Scheduled(fixedRate = 5000)
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting() throws Exception {
Thread.sleep(1000); // simulated delay
System.out.println("scheduled");
return new Greeting("Hello");
}
}
Run Code Online (Sandbox Code Playgroud)
这是app.jsp中的Connect()函数:
function connect() {
var socket = new SockJS('/gs-guide-websocket');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.send("/app/hello", {}, JSON.stringify({'name': "connect"}));
stompClient.subscribe('/topic/greetings', function (message) {
console.log("message"+message);
console.log("message"+(JSON.parse(message.body)));
showGreeting(JSON.parse(message.body).content);
});
});
}
Run Code Online (Sandbox Code Playgroud)
当index.jsp加载并按下连接按钮时,只有一次它在问候语中发出问候语,我应该如何让客户端每隔5秒显示一个"hello"消息?
我正在开发一个不是Spring boot而且还有spring mvc的项目.我的意思是我在我的项目中没有这个类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
Run Code Online (Sandbox Code Playgroud)
我有这三个类用于spring mvc的配置文件:
@Import(WebSocketConfig.class)
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "......")
public class MainConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/Content/**")
.addResourceLocations("/Content/");
registry.addResourceHandler("/Scripts/**")
.addResourceLocations("/Scripts/");
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver
= new InternalResourceViewResolver();
viewResolver.setPrefix("/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
Run Code Online (Sandbox Code Playgroud)
第二:
public class MainInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
public static HashMap<String, String> response_code = new HashMap<String, String>();
@Override
protected Class<?>[] getRootConfigClasses() …Run Code Online (Sandbox Code Playgroud) 我正在尝试这个示例教程,以便熟悉elasticsearch.但是运行项目会在intellij中出现这个错误:
org.elasticsearch.transport.NodeDisconnectedException: [][127.0.0.1:9300][cluster:monitor/nodes/liveness] disconnected
2017-08-22 13:32:10.489 ERROR 6372 --- [ main] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]
2017-08-22 13:32:10.669 INFO 6372 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
--ElasticSearch-->
client.type = transport
cluster.name = mkyong-cluster
name = Mahkizmo
network.server = false
node.client = true
transport.ping_schedule = 5s
<--ElasticSearch--
2017-08-22 13:32:10.751 INFO 6372 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display …Run Code Online (Sandbox Code Playgroud) 在大约像静态一些文章和教程这个和这个,据说使用静态还是不错的内存管理,因为静态变量类地区的类加载的时间变内存只有一次。
但是我的朋友告诉我,静态方法保存在堆栈中,因为管理堆比堆栈容易,并且垃圾收集器仅在堆上起作用,并且只要应用程序正在运行,就不会清除堆栈,因此请尽量少使用静态方法。您可以。
注意:
我已经在stackoverflow中阅读了有关堆栈内存的相同问题,但是我没有得到太多,因为使用“ PermGen空间”和我不知道的其他词,它们有些复杂和专业。
我希望有人简单地解释我朋友的预付款是否正确?
我知道这取决于,想象一下我既可以使用静态方法也可以使用静态方法进行设计。谈论哪个内存管理更好的方法?
在intellij idea中使用maven打包我的项目时,它给出了以下错误,我的java编译器版本也设置为1.8:-source 1.5 [ERROR]不支持菱形运算符(使用-source 7或更高版本启用菱形运算符)I真的很困惑,因为java版本和编译器版本都设置为1.8.
java ×5
maven ×3
spring ×3
spring-boot ×2
heap-memory ×1
javacompiler ×1
sockjs ×1
spring-mvc ×1
stack-memory ×1
static ×1
websocket ×1