如何解决Spring Boot-如何为spring.profiles.active = test禁用@Cacheable?
我只需要为spring.profiles.active = test的方法启用in_memory缓存。仅需要缓存最近10分钟内的请求。
现在,我将其设置如下:
@Profile("test")
@Configuration
class CachingConfig {
@Bean
fun cacheManager() = Caffeine.newBuilder()
.expireAfterWrite(10,TimeUnit.MINUTES)
.build<Any,Any>()
}
@Cacheable("request",key = "#dto.id")
fun request(dto: RequestDTO): Any {
...
}
@EnableCaching
@SpringBootApplication
@EnableConfigurationProperties
class Application
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java,*args)
}
build.gragle
test {
systemProperty "spring.profiles.active","test"
}
但是我害怕将其扩展,因为我不确定它在那里是否可以正常工作。
我不完全了解:spring.profiles.active = prod怎么用?
- 如果未针对以下原因引发cacheManager bean,将发生错误: 产品?
- 在默认情况下,会不会发生在生产弹簧上提高cacheManager的情况?
解决方法
您需要将import React from "react";
function Button(props) {
return (
<button id={props.id} value={props.value} onClick={props.onClick}>
{props.value}
</button>
);
}
export default Button;
从import SignUp from "./components/signUp.jsx";
import Login from "./components/login.jsx";
class App extends Component {
state = {
currentPage: "Login",};
pageSetter = ({ target }) => {
this.setState({ currentPage: target.value });
};
render() {
return (
<div>
{this.state.currentPage !== "Sign Up" && (
<Button id={"signUp"} value={"Sign Up"} onClick={this.pageSetter} />
)}
{this.state.currentPage !== "Login" && (
<Button id={"login"} value={"Login"} onClick={this.pageSetter} />
)}
{this.state.currentPage === "Login" && <Login />}
{this.state.currentPage === "Sign Up" && (
<SignUp pageSetter={this.pageSetter} />
)}
</div>
);
}
}
export default App;
移到class SignUp extends Component {
myChangeHandler = (event) => {
let attribute = event.target.id;
let value = event.target.value;
this.setState({ [attribute]: value });
};
onSubmit = (event) => {
event.preventDefault();
this.props.pageSetter.value = "Login"
this.props.pageSetter
};
render() {
console.log(this.state);
return (
<div>
<form onSubmit={this.onSubmit}>
<p>real_name:</p>
<input id="real_name" type="text" onChange={this.myChangeHandler} />
<p>username:</p>
<input id="username" type="text" onChange={this.myChangeHandler} />
<p>email:</p>
<input id="email" type="text" onChange={this.myChangeHandler} />
<p>password:</p>
<input
id="password"
type="password"
onChange={this.myChangeHandler}
/>
<p>picture</p>
<input id="picture" type="text" onChange={this.myChangeHandler} />
<button id="userSubmit" type="submit">
Submit
</button>
</form>
</div>
);
}
}
export default SignUp;
,才能使缓存仅适用于Profile =“ test”
@EnableCaching
通过这种方法,当非“测试”配置文件处于活动状态时,甚至不会将CachingConfig加载到应用程序上下文中
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。