spring-boot-demo | depth learning and actual combat | Object-Relational Mapping library
kandi X-RAY | spring-boot-demo Summary
Support
Quality
Security
License
Reuse
- Generate generator code .
- Convert a string to a numeric format
- Check if the given request should be overridden .
- Logs asynchronously .
- Save training data .
- Verify password .
- Build lock key .
- Check if the user has permission
- parse JWT
- Returns a page of tables .
spring-boot-demo Key Features
spring-boot-demo Examples and Code Snippets
Trending Discussions on spring-boot-demo
Trending Discussions on spring-boot-demo
QUESTION
I have a service managed by spring, I put @Validated annotation on that service refer to this article, it tells that spring will do the validation for us, we don't even need to valid it manually.
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
@Component
@Validated
public class MyService {
public void execute(@Valid MyRequest request) {
//todo
}
}
MyRequest is a DTO which will be validated by spring
import lombok.Data;
import javax.validation.constraints.Positive;
@Data
public class MyRequest {
@Positive(message = "id should be positive")
private Long id;
}
here is my controller, in some reason, I don't want to do the validation in controller.
@Controller
public class MainController {
@Autowired
private MyService service;
@RequestMapping(value = "/execute", method = {GET, POST})
@ResponseBody
public MyResponse execute() {
MyResponse res = new MyResponse();
service.execute(new MyRequest());
res.setHtmlText("hello world");
return res;
}
}
when I visit the url: http://localhost:8001/execute it doesn't give me any exception and show the result hello world
here is the maven dependency
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.5.4
com.fudy
spring-boot-demo
0.0.1-SNAPSHOT
spring-boot-demo
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.projectlombok
lombok
org.springframework.boot
spring-boot-starter-validation
javax.validation
validation-api
org.hibernate.validator
hibernate-validator
org.springframework.boot
spring-boot-maven-plugin
however after I replace @Positive to @NotNull, it works fine
import lombok.Data;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
@Data
public class MyRequest {
//@Positive(message = "id should be positive")
@NotNull(message = "id should not be null")
private Long id;
}
ANSWER
Answered 2022-Jan-04 at 09:04It works as it should. The validator associated with @Positive
, the PositiveValidatorForLong
accepts null
values as valid. So it will only validate actual values, not null
.
Basically you need them both to fullfil your requirements, so both @Positive
and @NotNull
to only allow positive values.
pro-tip: As you already have the spring-boot-starter-validation
dependency you don't need the additional validation-api
and hibernate-validator
dependencies, those are added already.
QUESTION
I'm trying to use the jasypt-spring-boot and deploy it to a Tomcat server as war. How to pass the encryptor password, in this case, to ensure the encrypted values could be read? All the provided example are about running a jar
file or a Spring Boot app as follows:
java -Djasypt.encryptor.password={my-password-to-decrypt} -jar target/jasypt-spring-boot-demo-0.0.1-SNAPSHOT.jar
May be add some settings to catalina.properties
file in the Tomcat conf
folder as we do for example when defining active profile?
ANSWER
Answered 2021-Apr-13 at 16:34I figured out how to achieve that:
- create a
setenv.sh
file in CATALINE_HOME/bin folder - add the following entry to set the environment variable on the Tomcat startup:
export JASYPT_ENCRYPTOR_PASSWORD=your-password
- save and restart Tomcat.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install spring-boot-demo
You can use spring-boot-demo like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the spring-boot-demo component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page