我正在开发一个Spring Boot项目并使用Spring Data JPAwithHibernate作为JPA实现。
目前在我的application.yml文件中我有以下属性:
spring:
jpa:
show-sql: true
properties:
hibernate:
format_sql: true
generate_statistics: true
hibernate:
ddl-auto: none
dialect: org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud)
Hibernate 属性有不同的前缀(spring.jpa.properties.hibernate和spring.jpa.hibernate)
具有这些差异的目的是什么?它们可以互换使用,这意味着我可以替换spring.jpa.properties.hibernate.format_sql为spring.jpa.hibernate.format_sql?
我正在使用Spring Boot 3,据我了解,它应该支持RFC 7807,又名“问题详细信息”,开箱即用。但是,我不知道如何启用Spring Boot(web)以这种格式返回错误。默认情况下,它似乎以标准 SpringJSON格式返回:
{
"timestamp": "2012-04-25T10:56:28.294+0000",
"path": "/api/v1/some-resource",
"status": 400,
"error": "Bad Request",
"exception": "java.lang.IllegalArgumentException"
}
Run Code Online (Sandbox Code Playgroud)
如何在 Spring Boot 3 中启用“问题详细信息”(RFC 7807)?
为了
<dependencies>
...
<dependency>
<groupId>com.manuel.jordan</groupId>
<artifactId>some module</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<id>create-fat-jar</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>somename</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
该插件运行良好,但总是出现此消息:
[WARNING] moduleA-0.0.1-SNAPSHOT.jar,
moduleB-0.0.1-SNAPSHOT.jar,
.... more
moduleN-0.0.1-SNAPSHOT.jar define 1 overlapping resource:
[WARNING] - META-INF/MANIFEST.MF
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] …Run Code Online (Sandbox Code Playgroud) 我有两个模块网络和业务.我已将业务纳入网络.但是,当我尝试将业务中的服务接口包含在web中时@autowired,它正在给予org.springframework.beans.factory.NoSuchBeanDefinitionException.
所以,基本上@SpringBootApplication无法扫描@Service来自业务模块.
它是简单的,我想念?
如果我@Bean在@SpringBootApplication课堂上添加该服务,它工作正常.
码:
package com.manish;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class SpringBootConfiguration {
public static void main(String[] args) {
SpringApplication.run(SpringBootConfiguration.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
模块1中的类,从模块2调用类:
package com.manish.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.co.smithnews.pmp.service.contract.UserRegistrationService;
@RestController
@RequestMapping("/testManish")
public class SampleController {
@Autowired
private SampleService sampleService;
....
}
Run Code Online (Sandbox Code Playgroud)
第2单元:
package com.manish.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SampleServiceImpl …Run Code Online (Sandbox Code Playgroud) 我正在尝试Filter仅将自定义添加到特定的 URL,但是过滤器会应用于每个请求,无论 URL 和方法如何,是否有人知道使用 Spring Security 的最新版本来修复此问题的正确方法,即不使用WebSecurityConfigurerAdapter,因为它将被弃用。它符合:
这里有很多类似的问题,但它们要么对我不起作用,要么使用“旧”方法,例如:
我暴露了许多端点,它们都遵循该模式:/api/**但是我需要为特定端点提供一些身份验证:/api/some/url以及特定方法(GET在本例中),我该如何正确执行此操作?
注意:端点 URL 全部位于/api/*(它们应该称为嵌套吗?)
我的安全配置如下所示:
@EnableWebSecurity
public class SecurityConfig {
private MyFilter myFilter;
public SecurityConfig(MyFilter pif) {
myFilter = pif;
}
/**
* Handling AuthZ & AuthN for most APIs. No AuthZ & AuthN.
*/
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SecurityFilterChain defaultSecurity(HttpSecurity http) throws Exception { …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring和EhCache
我有以下方法
@Override
@Cacheable(value="products", key="#root.target.PRODUCTS")
public Set<Product> findAll() {
return new LinkedHashSet<>(this.productRepository.findAll());
}
Run Code Online (Sandbox Code Playgroud)
我有其他使用@Cacheable和@CachePut以及@CacheEvict的方法.
现在,假设数据库返回100个产品并且它们被缓存key="#root.target.PRODUCTS",然后其他方法将插入 - 更新 - 删除项目到数据库中.因此,通过它缓存的产品key="#root.target.PRODUCTS"不再相同,例如数据库.
我的意思是,检查以下两种方法,他们能够更新/删除一个项目,同一项目缓存在另一个key="#root.target.PRODUCTS"
@Override
@CachePut(value="products", key="#product.id")
public Product update(Product product) {
return this.productRepository.save(product);
}
@Override
@CacheEvict(value="products", key="#id")
public void delete(Integer id) {
this.productRepository.delete(id);
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以通过更新/删除位于缓存中的项目key="#root.target.PRODUCTS",如果产品已更新,则为100,如果删除了产品,则为499.
我的观点是,我想避免以下情况:
@Override
@CachePut(value="products", key="#product.id")
@CacheEvict(value="products", key="#root.target.PRODUCTS")
public Product update(Product product) {
return this.productRepository.save(product);
}
@Override
@Caching(evict={
@CacheEvict(value="products", key="#id"),
@CacheEvict(value="products", key="#root.target.PRODUCTS")
})
public void delete(Integer id) {
this.productRepository.delete(id); …Run Code Online (Sandbox Code Playgroud) 我正在做一些关于Java 8并发性的实验
在ScheduledThreadPoolExecutor API中
我可以看到以下两个签名:
schedule(Callable<V> callable, long delay, TimeUnit unit)
schedule(Runnable command, long delay, TimeUnit unit)
Run Code Online (Sandbox Code Playgroud)
一个为Callable一个为一个Runnable
我也可以在API中看到以下两个:
scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么不存在两个等价物 Callable
scheduleAtFixedRate(Callable<V> callable, long initialDelay, long period, TimeUnit unit)
scheduleWithFixedDelay(Callable<V> callable, long initialDelay, long delay, TimeUnit unit)
Run Code Online (Sandbox Code Playgroud)
我需要为操作检索一个布尔结果.
谢谢.
我正在与:
我有以下顺序
DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;
Run Code Online (Sandbox Code Playgroud)
它通过Java(JDBC)失败并通过MySQLWorkBench失败,错误消息是关于FK Child约束(我没有确切的错误消息),通过谷歌我做了一个研究,我发现了两次相同的有效解
好吧,我做了以下事情:
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;
SET FOREIGN_KEY_CHECKS=1;
Run Code Online (Sandbox Code Playgroud)
它再次起作用,只是玩,我试图再次执行
DROP TABLE IF EXISTS invoicedetail;
DROP TABLE IF EXISTS invoiceheader;
DROP TABLE IF EXISTS product;
Run Code Online (Sandbox Code Playgroud)
确保SELECT @@FOREIGN_KEY_CHECKS;返回1
那么原始的错误消息不会再出现.
我再次对谷歌进行了研究,发现了以下内容:
它说: It is session-based
好吧,即使在:
我已经在 app类ComponentScan中使用注释,但是如果我仅使用此注释,它将在获取存储库引用时出现问题。因此,为了克服这个问题,我正在使用和注释。MainSpring BootEntityScanEnableJpaRepositoriescomponentScan
@EntityScan(basePackages={"com.gonkar.fleetms.models"})
@EnableJpaRepositories(basePackages={"com.gonkar.fleetms.repositories"})
Run Code Online (Sandbox Code Playgroud)
所以我的问题是为什么需要使用其他两个注释?如果我已经在使用@ComponentScan.
我有windows 10 home,安装在哪里Ubuntu
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Run Code Online (Sandbox Code Playgroud)
我已经安装了Redis 5.0.5(它主要是make和make install)
当我启动服务器时 redis-server它会显示一些警告。
我已经删除了一个关于 overcommit_memory
但是关于:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
Run Code Online (Sandbox Code Playgroud)
我已经阅读了这两个链接:
因此,两者都表示执行以下操作:
/etc目录rc.local文件,sudo vim rc.local sysctl -w net.core.somaxconn=65535 …