我需要从.yml文件加载一个属性,该文件包含应用程序可以从中读取文件的文件夹的路径.
我正在使用以下代码注入属性:
@Value("${files.upload.baseDir}")
private String pathToFileFolder;
Run Code Online (Sandbox Code Playgroud)
.yml用于开发的文件位于src/main/resources/config/application.yml生成器中,使用以下命令运行应用程序,以覆盖开发设置:
java -jar app.jar --spring.config.location=/path/to/application-production.yml
Run Code Online (Sandbox Code Playgroud)
Spring Boot文档说:
SpringApplication将从以下位置的application.properties文件加载属性,并将它们添加到Spring环境中:
当前目录的A/config子目录.
当前目录
一个classpath/config包
类路径根
以及:
您还可以使用YAML('.mil')文件替代'.properties'.
该.yml文件包含:
{...}
files:
upload:
baseDir: /Users/Thomas/Code/IdeaProjects/project1/files
{...}
Run Code Online (Sandbox Code Playgroud)
我的Application班级注释为:
@SpringBootApplication
@EnableCaching
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我得到一个例外:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'files.upload.baseDir' in string value "${files.upload.baseDir}"
Run Code Online (Sandbox Code Playgroud)
我是否必须使用YamlPropertySourceLoader该类或添加特殊注释才能.yml在Spring Boot中启用支持?
编辑:该.yml文件包含一些其他属性,这些属性由Spring Boot成功加载,如dataSource.XXX或hibernate.XXX.
我有一个返回图像的base64版本的服务.现在我想在一个src标签中使用base64字符串img.该服务提供base64版本http://localhost:8080/file/301/base64.
base64字符串如下所示:
data:image/gif;base64,iVBORw0KGgo ...
Run Code Online (Sandbox Code Playgroud)
我img页面上的标签目前如下所示:
<img alt="" src="http://localhost:8080/file/301/base64" style="height:836px; width:592px">
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个运行?
我想更改计费计划的金额,但在尝试更改时出现错误。如果计划已经有与之相关的协议,是否可以更改计划的条款 (payment_definitions)?
要求:
curl -v -k -X PATCH 'https://api.sandbox.paypal.com/v1/payments/billing-plans/[plan id]' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-d '[
{
"path": "/payment_definitions/[payment_definitions_id]/amount",
"value": {
"currency": "EUR",
"value" : "10"
},
"op": "replace"
}
]'
Run Code Online (Sandbox Code Playgroud)
回复:
{
"name":"BUSINESS_VALIDATION_ERROR",
"details":[
{
"field":"validation_error",
"issue":"Invalid Path provided."
}
],
"message":"Validation Error.",
"information_link":"https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_VALIDATION_ERROR",
"debug_id":"183e87c07085e"
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个要发布到npmjs的Angular 6库。工作区(示例)和库在GitHub上进行了版本控制。我已经使用Angluar-CLI的命令创建了库npm library lib-name。
这些项目README.md位于工作区项目的根文件夹中。如Medium指南中所述,我已经构建了库并使用以下命令将其发布到npm:
ng build ng-as-multiselect-dropdown --prod
cd dist/ng-as-multiselect-dropdown
npm publish
Run Code Online (Sandbox Code Playgroud)
该库现在在npmjs上发布,但npmjs无法读取该库,README.md因为自述文件不在库代码中,而在工作区项目中:
"Unable to find a readme for @austrianstandards/ng-as-multiselect-dropdown@1.0.0"
Run Code Online (Sandbox Code Playgroud)
如何发布库并将其包含README.md在构建中,以便自述文件都显示在GitHub和npmjs上?
ConstraintValidator在类中使用依赖注入时,在遇到依赖注入时遇到了意外的行为。
实体类:
@Entity
@ValidDemoEntity
public class DemoEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
验证批注:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {DemoEntityValidator.class})
public @interface ValidDemoEntity {
String message() default "{some.demo.validator.message}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Run Code Online (Sandbox Code Playgroud)
验证器:
public class DemoEntityValidator implements ConstraintValidator<ValidDemoEntity, DemoEntity> {
private DemoEntityRepository demoEntityRepository;
public DemoEntityValidator(DemoEntityRepository demoEntityRepository) {
this.demoEntityRepository = demoEntityRepository;
}
@Override
public void initialize(ValidDemoEntity constraintAnnotation) {
}
@Override
public boolean isValid(DemoEntity demoEntity, ConstraintValidatorContext constraintValidatorContext) {
return true;
}
} …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试设置Spring 4/Hibernate 4/PostgreSQL项目.当我为PostgreSQL添加JDBC驱动程序时,我得到以下异常:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/Thomas/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.7/8095d0b9f7e0a9cd79a663c740e0f8fb31d0e2c8/slf4j-simple-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/Thomas/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.2/b316e9737eea25e9ddd6d88eaeee76878045c6b2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Run Code Online (Sandbox Code Playgroud)
我的application.properties文件:
jdbc.driverClassName = org.postgresql.Driver
jdbc.url = jdbc:postgresql://localhost:5432/itcareer
jdbc.username = postgres
jdbc.password = postgres
hibernate.dialect = org.hibernate.dialect.PostgreSQL9Dialect
hibernate.show_sql = true
hibernate.format_sql = true
hibernate.hbm2ddl.auto = update
Run Code Online (Sandbox Code Playgroud)
HibernateConfiguration.java
package at.itcareer.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateTransactionManager;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableTransactionManagement
@ComponentScan({ "at.itcareer.config" })
@PropertySource(value …Run Code Online (Sandbox Code Playgroud) 有没有办法告诉Thymeleaf添加参数到标签而不是覆盖它们?
例:
<div class="a" th:class=${x ? 'b' : 'c'}>
Run Code Online (Sandbox Code Playgroud)
应该导致
<div class="a b">
Run Code Online (Sandbox Code Playgroud)
要么
<div class="a c">
Run Code Online (Sandbox Code Playgroud)
问候
private int field;
public void f(int n) {
n = n + field;
field = field + n;
n = n + 2;
}
public void g() {
field = 2;
f(field);
}
Run Code Online (Sandbox Code Playgroud)
调用后字段的最终值是g()多少?我知道答案是6但有人可以解释一下原因吗?