我正在使用Ant来构建一些Java项目.
在某些情况下,我lib/在JAR文件的表单中有一个包含外部依赖项的目录.
在构建期间,我创建了一个捆绑的jar,它包含项目的代码以及依赖项,通过向目录中的zipfileset每个jar添加bundle jar文件a lib/.
问题是,每次我添加一个jar或更改名称时,我都需要记住更新build.xml文件,因为我找不到以zipfilesets自动方式添加这些文件的方法,这些方式将包括特定模式中的所有jar(例如lib/*.jar).
这样做有更好的方法吗?
我已经考虑为此编写自己的Ant任务,或者使用Groovy的ant API以编程方式执行此操作,但是想知道是否有使用"vanilla"ant的方法.
深入研究Spring Batch,我想知道如何在作业的不同步骤之间共享数据?
我们可以使用JobRepository吗?如果是的话,我们怎么做?
有没有其他方法可以做到/达到同样的目的?
我试图在Spring中编写自定义JSON反序列化器.我想在大多数字段中使用默认序列化程序,并为少数属性使用自定义反序列化程序.可能吗?我这样做是因为,大部分属性都是值,所以对于这些我可以让杰克逊使用默认的反序列化器; 但很少有属性是引用,所以在自定义反序列化器中,我必须查询数据库以获取引用名称并从数据库中获取引用值.
如果需要,我会展示一些代码.
我只想听听Hibernate专家关于基于Hibernate/JPA项目的数据库模式生成最佳实践的意见.特别:
项目刚刚开始时使用什么策略?是否建议让Hibernate在此阶段自动生成模式,还是最好从项目的最早阶段手动创建数据库表?
假设在整个项目中使用Hibernate生成模式,是否最好在系统发布到生产之前禁用自动模式生成并手动创建数据库模式?
在系统投入生产之后,维护实体类和数据库模式的最佳实践是什么(例如,添加/重命名/更新列,重命名表等)?
我正在使用Spring Validator实现来验证我的对象,我想知道你如何为这样的验证器编写单元测试:
public class CustomerValidator implements Validator {
private final Validator addressValidator;
public CustomerValidator(Validator addressValidator) {
if (addressValidator == null) {
throw new IllegalArgumentException(
"The supplied [Validator] is required and must not be null.");
}
if (!addressValidator.supports(Address.class)) {
throw new IllegalArgumentException(
"The supplied [Validator] must support the validation of [Address] instances.");
}
this.addressValidator = addressValidator;
}
/**
* This Validator validates Customer instances, and any subclasses of Customer too
*/
public boolean supports(Class clazz) {
return Customer.class.isAssignableFrom(clazz);
} …Run Code Online (Sandbox Code Playgroud) 我写了一些代码.我想把BaseQuestionClass中的questionId字段设为Autogenerated.Any解决方案呢?我没有使用jpa jar.so我不能使用@Generatedvalue注释.所以我们如何在这里显示这个字段是自动生成的.代码如下.
的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>audit_project</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
BaseQuestion.java …
我从一张桌子中得到了奇怪的结果.请考虑下表:
USERID TICKETSASSIGNED
1 0
100 0
101 0
102 0
103 0
Run Code Online (Sandbox Code Playgroud)
现在,如果我有以下sql:
SELECT TOP 1 USERID
FROM TABLEX
ORDER BY TICKETSASSIGNED
Run Code Online (Sandbox Code Playgroud)
我期望得到的结果是"1",但大多数时候我得到"100",第二个记录.因为TICKETSASSIGNED值都是"0",所以它会随机选择它认为是TOP 1的那个,因为这是我订购的字段.要在这种情况下获得正确的"1"值,我还必须订购USERID.
有任何想法吗?
当我的应用程序准备退出时,通过关闭窗口或调用System.exit()方法.我是否必须手动停止我可能创建的线程,或者Java会为我处理这些线程吗?
Spring Boot使用自动初始化基础日志系统LoggingApplicationListener.如果我正在开发的应用程序是孤立的或独立的,那么这是一件好事.
但是我正在开发一个Web应用程序,它将部署到WSO2 Application Server中,它提供统一的日志记录(使用log4j),具有中央日志级别管理(运行时通过Web界面),业务报告等功能.
如果我"按原样"使用Spring Boot,它会完全记录所有内容.我的第一个镜头是,删除spring-boot-starter-logging并手动添加slf4j-api为provided.这在一定程度上起作用,因为LoggingApplicationListener现在覆盖了WSO2提供的全局logmanager的设置(甚至导致全局appender被关闭).
我想出的唯一"解决方案"是通过反射删除监听器.然后Spring Boot开始表现得完全正常(通过全局记录器记录,而不是覆盖预定义的日志级别,输出格式,appender等)
那个"解决方案"看起来像这样:
@SpringBootApplication
public class MyApp extends SpringBootServletInitializer {
public static void main(String... args) {
SpringApplication.run(MyApp.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
try {
Field appField = SpringApplicationBuilder.class.getDeclaredField("application");
appField.setAccessible(true);
SpringApplication app = (SpringApplication)appField.get(builder);
Field listenersField = SpringApplication.class.getDeclaredField("listeners");
listenersField.setAccessible(true);
List<ApplicationListener<?>> listeners = (List<ApplicationListener<?>>) listenersField.get(app);
for (int i = listeners.size() - 1; i >= 0; --i) {
if (listeners.get(i) instanceof LoggingApplicationListener) { …Run Code Online (Sandbox Code Playgroud) java ×5
spring ×3
spring-boot ×2
angular ×1
ant ×1
concurrency ×1
hibernate ×1
jackson ×1
jar ×1
jpa ×1
json ×1
junit ×1
logging ×1
mocking ×1
mongodb ×1
spring-batch ×1
spring-data ×1
sql ×1
validation ×1
wso2carbon ×1