Spring boot Java
您正在調用executeUpdate()進行選擇查詢。試著改用getSingleResult()。 @Overridepublic long getCountByEmail(String email) { Session session = entityManager.unwrap(Session.class); String query = "SELECT count(e) FROM User e WHERE e.email = :email"; TypedQuery<Long> typedQuery = session.createQuery(query, Long.class); typedQuery.setParameter("email", email); return typedQuery.getSingleResult();} OR @Overridepublic long getCountByEmail(String email) { String query = "SELECT count(e) FROM User e WHERE e.email = :email"; TypedQuery<Long> typedQuery = entityManager.createQuery(query, Long.class); typedQuery.
如果切換開關,如何使用串行端口監聽?
為了節省您向電子交易所重新寄存的工作: 根據本文件,將CTS設置為開啟意味著相對于GND,CTS線路上的電壓至少為+3V。類似地,設置CTS off意味著CTS線路上相對于GND的電壓至少為-3V。因此,您需要兩個電壓源,一個用于>+3V(接地到串行接地),另一個用于<-3V(加上串行接地)。 根據文件,DSR的功能類似。 而且,你的開關看起來像一個SPST。如果要避免使用電阻器,至少需要一個SPDT。
如何讓postgres監聽容器的新暴露端口(而不是5432)?
您有多種選擇: 選項1:定義自己的postgresql.conf url_db: build: context: ./api/services/url/db dockerfile: Dockerfile container_name: "url_db" command: postgres -c "config_file=/etc/postgresql/postgresql.conf" environment: POSTGRES_USER: gorm POSTGRES_PASSWORD: gorm POSTGRES_DB: gorm POSTGRES_HOST: url_db ports: - 5433:5433 volumes: - /path/to/config:/etc/postgresql/postgresql.conf Postgres在容器中的/usr/share/postgresql/postgresql.conf.sample有一個示例配置。 要運行配置: docker run -i --rm postgres cat /usr/share/postgresql/postgresql.conf.sample > my-postgres.conf 選項1:覆蓋RUN命令 url_db: build: context: ./api/services/url/db d
Spring boot enity
進口是錯誤的。 導入定義的用戶類,而不是Spring安全用戶類。 刪除此org.springframework.boot.autoconfigure.security.SecurityProperties.User并導入您的用戶類。
spring boot Tomcat
最后,我解決了這個問題。{80h2啟動程序時需要使用{80h2}來啟動依賴項。
Spring MVC Controller
問題在于這一行: when(customerService.update(oneCustomer.getId(), oneCustomer)).thenReturn(oneCustomer); 你應該把它改成 when(customerService.update(eq(oneCustomer.getId()), any())).thenReturn(oneCustomer); 因為您的put請求主體是JSON,而不是真正的Customer,所以when...thenReturn語句沒有像您預期的那樣工作良好。被模擬的customerService默認返回空值。這就是為什么你得到了一個空洞的回答。因此,你必須糾正參數匹配器,使其正確。
使用thymeleaf從前端更改Spring Boot應用程序的默認端口
如這里所述,您可以這樣設置服務器端口: import org.springframework.boot.web.server.ConfigurableWebServerFactory;import org.springframework.boot.web.server.WebServerFactoryCustomizer;import org.springframework.stereotype.Component; @Componentpublic class AppCustomContainer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> { @Override public void customize(ConfigurableWebServerFactory factory) { factory.setPort(1234); }} 代替1234,您可以使用文件來存儲端口(更改端口時)并在啟動時加載它 之后,您可以按以下說明重新啟動應用程序: 添加執行器和spring-cloud: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spr
Docker-compose“端口”:監聽多個IP地址/IP范圍
Listening to a single IP address似乎不正確。該服務正在偵聽IP地址。 假設你的虛擬機有兩個網絡接口(以太網卡): 網絡1→ 子網:10.0.0.0/24和IP10.0.0.100網絡2→ 子網:10.0.1.0/24和IP10.0.1.200 如果您設置了127.0.0.1:80:80,這意味著您的服務在127.0.0.1的(本地主機)端口80監聽。 如果您想從10.0.0.0/24子網訪問服務,您應該設置10.0.0.100:80:80并使用http://10.0.0.100:80地址,以便能夠從外部主機連接您的容器 如果要同時從多個網絡訪問服務,可以將容器端口綁定到多個端口,其中IP是連接源IP): ports:- 10.0.0.100:80:80- 10.0.1.200:80:80- 127.0.0.1:80:80 如果存在防火墻并限制了網絡,不要忘記在VM的防火墻上打開80端口
Golang如何獲取端口監聽服務的詳細信息
command := "lsof -i:55555"cmd := exec.Command("/bin/bash", "-c", command)bytes,err := cmd.Output()if err != nil { log.Println(err)}resp := string(bytes)log.Println(resp) 您可以通過golang代碼執行shell
Spring Boot
@Autowired僅在為應用程序旋轉應用程序上下文時有效。用@SpringBootTest注釋測試類,它告訴測試啟動整個spring應用程序上下文,它應該可以工作。
如何使用warp監聽多個端口?
您可以啟動兩個單獨的實例并同時運行它們: tokio::join!( warp::serve(routes).run(([127, 0, 0, 1], 3030)), warp::serve(routes).run(([127, 0, 0, 1], 3031)),); 靈感來源于在不同端口上運行多個actix應用程序
獲取節點端口是未定義的,即使我看不到任何監聽端口的內容
在.env中有變量port,但要檢查PORT是否已定義(沒有定義)。在.env中將port更改為PORT。 編輯:我還建議刪除.env中的空格。
httpmediatypenotacceptableexception spring mvc
感謝@Andreas RootConfig.class @EnableWebMvc @Configuration public class RootConfig implements WebMvcConfigurer { @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(byteArrayHttpMessageConverter()); converters.add(resourceHttpMessageConverter()); } @Bean public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() { ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter(); arrayHttpMessageConverter.setSupportedMediaTypes(getSupportedMediaTypes()); return arrayHttpMessageConverter; } @
將現有的Spring MVC項目遷移到Spring Boot
沒有銀彈遷移指南可以做到這一點,但也許https://www.baeldung.com/spring-boot-migration可以給你一些提示來簡化你的任務。我想說的是,有一些關鍵點: 努力使用Spring Boot Starters(它們捆綁了給定主題的所有必要依賴項,例如安全性); 努力使用Spring Boot父級定義的依賴項版本,而不是您自己的版本。這保證您在手動更新可能不兼容的依賴項版本時不會遇到問題; 學習并理解自動配置是如何工作的,因為它將幫助您更好地掌握Spring Boot在引擎蓋下是如何工作的(在調試一些奇怪的行為時,它可能會幫助您)。
Spring Boot和Spring Integration。問題
既然你做了new Integration();,你肯定不會有依賴注入,因為不涉及控制容器的反轉。盡管還不清楚為什么你需要new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/http-outbound-config.xml")如果你已經做了Spring Boot和那個合適的@ImportResource。 對@ImportResource進行Spring集成XML配置的最佳方法。然后需要訪問SpringApplication.run()和getBean(Integration.class)的ApplicationContext來調用start()方法。但是你完全需要忘記new Integratio()。Spring將為Integration管理一個bean,然后依賴注入就可以工作了。 異步模式可以用ExecutorChannel在Spring Integration中實現。因此,當您向這個通道發送消息時,邏輯將在另一個thread上處理。但是,不清楚為什么要聲明這樣的要求,因為您仍然要通過replyChannel.receive()來阻止。。。盡管這應該在單獨的SOthread中解決。 Camel VSSpring Integration問題超出了StackOverflow策略。 在這個