是否可以使用spring boot列出我配置的所有休息端点?执行器在启动时列出所有现有路径,我想要类似于我的自定义服务,所以我可以检查启动是否正确配置了所有路径并将此信息用于客户端调用.
我该怎么做呢?我在我的服务bean上使用@Path/ @GET注释并通过注册它们ResourceConfig#registerClasses.
有没有办法查询所有路径的配置?
更新:我通过注册REST控制器
@Bean
public ResourceConfig resourceConfig() {
return new ResourceConfig() {
{
register(MyRestController.class);
}
};
}
Run Code Online (Sandbox Code Playgroud)
Update2:我希望有类似的东西
GET /rest/mycontroller/info
POST /res/mycontroller/update
...
Run Code Online (Sandbox Code Playgroud)
动机:当spring-boot应用程序启动时,我想打印出所有已注册的控制器及其路径,因此我可以停止猜测要使用哪些端点.
在解析我的ivy.xml时,我得到了一长串错误,所有错误都是"未知的解析器XYZ".我知道解析器,它用于同一个项目但不同的任务.据我所知,用于创建缓存条目的解析器是存储的,而后续解析器无法确定.
问题是:我该如何避免这种情况?像这样的似乎不是一个错误,更像是一个警告,因为我能够解决所有依赖关系并继续编译.
有没有办法在启动Spring Boot应用程序时在控制台中显示Flyway迁移步骤?迁移工作正常.我只是没有看到任何关于它的日志.
我检查过飞路物业,但没有任何关于它的信息.
有没有办法控制flyway中可重复迁移脚本的执行顺序?我希望在校验和更改的所有其他可重复或版本化脚本之后运行可重复的迁移脚本.
好像我错过了一些东西:自动注入数据源工作,但DataSourceTransactionManager的注入失败.
依赖关系:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
码:
@SpringBootApplication
public class MainApplication {
@Autowired
private DataSource dataSource;
// this fails
@Autowired
private DataSourceTransactionManager transactionManager;
public static void main(String... args) {
SpringApplication.run(MainApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
我期望DataSourceTransactionManagerAutoConfiguration会处理它,但事实并非如此.有线索吗?
示例在github上:https://github.com/jangalinski/springboot-playground
我有一个ConfigurationProperties课,想要使用它进行测试junit.但对象总是如此null.以下代码中可能缺少什么?
@EnableAutoConfiguration
@ComponentScan
@EnableConfigurationProperties(MyProperties.class)
public class AppConfig {
}
@Service
public class MyService {
@Autowired
private MyProperties props;
public void run() {
props.getName();
}
}
@Component
@ConfigurationProperties(prefix = "my")
public class MyProperties {
private String name;
//getter,setter
}
Run Code Online (Sandbox Code Playgroud)
application.properties:
my.name=test
Run Code Online (Sandbox Code Playgroud)
测试:
@Configuration
@ComponentScan(basePackageClasses = {MyService.class, MyProperties.class},
includeFilters = @ComponentScan.Filter(value = {MyService.class, MyProperties.class},
type = FilterType.ASSIGNABLE_TYPE),
lazyInit = true
)
@PropertySources(
@PropertySource("application.properties")
)
class AppTest {
@Bean
public static PropertySourcesPlaceholderConfigurer propertiesResolver() {
return new PropertySourcesPlaceholderConfigurer(); …Run Code Online (Sandbox Code Playgroud) 我使用以下内容:
@Entity
@Data
@Builder
@NoArgsConstructor(force = true)
public class User {
private String id;
private String firstName;
private String lastName;
}
Run Code Online (Sandbox Code Playgroud)
我想要实现的目标:对于JPA用法,我需要一个带有noArgConstructor的POJO,getters/setter和equals/hashCode/toString.
例如创建(例如在测试中)我想使用User.builder().build();
问题:它没有编译,NoArgConstructor与RequiredFieldsConstructor似乎存在问题:
Error:(15, 1) java: constructor User in class x.y.z.User cannot be applied to given types;
required: no arguments
found: java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String
reason: actual and formal argument lists differ in length
Run Code Online (Sandbox Code Playgroud)
更新:当我尝试通过new构建器()工作创建新实体时发生错误.
我错过了什么?是不是可以同时使用@ Data,@ Entity和@Builder?
是否有可能(如果是这样:如何)在camunda BPM中向jobexecutor添加自定义作业?我的要求是通过Timer或Loop执行与进程相关的Service.我不想直接在BPMN中对此进行建模,因为它实际上并不是流程的一部分.我可以启动只包含一个异步服务任务的其他任意进程来实现这一目标,但我更愿意直接向作业队列添加一个包含SOAP/REST/RMI调用的方法调用,而无需额外的努力.以前有人试过吗?
有没有办法在不使用 spring boot 的情况下在普通 spring web mvc 应用程序中启用 yaml 配置(而不是属性文件)并支持 @Value 注释。
我搜索了很多,到处都使用弹簧靴。我对使用 spring boot 不感兴趣,因为它非常重,并且为自动设置配置了许多依赖项。
任何帮助,将不胜感激......
当我配置Spring Boot应用程序时,我可以通过静态main方法中的运行配置禁用横幅.到现在为止还挺好.
但如果我有以下内容怎么办:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes={MyApplication.class})
public class MyApplicationTest {
....
}
Run Code Online (Sandbox Code Playgroud)
当我运行此测试时,它不使用静态main方法并显示横幅,这使得更难关注相关的日志记录语句.
是否有可用于模拟的开关或配置注释new SpringApplication(MayApplicationclass).setShowBanner(false)...?
java ×6
spring-boot ×4
spring ×3
flyway ×2
junit ×2
ant ×1
camunda ×1
datasource ×1
ivy ×1
jersey ×1
jersey-2.0 ×1
logging ×1
lombok ×1
rest ×1
spring-mvc ×1
spring-test ×1