我在SpringBoot项目中使用@SneakyThrows Lombok功能.当CGLIB代理实现它抛出java.lang.Exception时,我遇到此功能的问题
:预期的异常,但是<java.lang.reflect.UndeclaredThrowableException>.
它可以以某种方式修复吗?
提供示例.
有接口和两个实现.
public interface SneakyThrowsExample {
void testSneakyThrows();
}
Run Code Online (Sandbox Code Playgroud)
简单的实施
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component(value = "simpleSneakyThrowsExample")
public class SimpleSneakyThrowsExample implements SneakyThrowsExample {
@Override
@SneakyThrows
public void testSneakyThrows() {
throw new IOException();
}
}
Run Code Online (Sandbox Code Playgroud)
和@Transactional实现.CGLIB将代理此实现.
import lombok.SneakyThrows;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
@Component(value = "transactionalSneakyThrowsExample")
public class TransactionalSneakyThrowsExample implements SneakyThrowsExample {
@Override
@SneakyThrows
@Transactional
public void testSneakyThrows() {
throw new IOException();
}
}
Run Code Online (Sandbox Code Playgroud)
创建@SpringBootTest测试并注入这两个实现 …
The Console Launcher that comes with JUnit Platform (from JUnit 5) produces a quite nice summary view at the end. The Maven Surefire plugin, however, has a very simple output.
Is it possible to create with Surefire output similar to what the launches creates?
我可以调用mvn cobertura:cobertura
仪器,运行单元测试(使用surefire
),并生成报告.
我可以调用mvn verify
运行单元测试和集成测试(使用failsafe
Maven插件).
但是,我如何调用Maven来测试,运行单元测试和集成测试,以及生成报告?使用Cobertura Maven插件运行集成测试的答案对我来说不起作用,而且我也不想打电话verify
给每个Cobertura跑,但仅限于夜间报道.
我试图用Thymeleaf模板Spring应用程序发送邮件时,我从这里走的参考 https://github.com/thymeleaf/thymeleafexamples-springmail/
我没有得到任何错误但仍然无法正常工作..我使用github中给出的相同代码仍然没有运气...任何人都可以建议怎么做?
以下是用于发送邮件的方法...
public void sendSimpleMail(
final String recipientName, final String recipientEmail, final Locale locale)
throws MessagingException {
final Context ctx = new Context(locale);
ctx.setVariable("name", recipientName);
ctx.setVariable("subscriptionDate", new Date());
ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
message.setSubject("Example HTML email (simple)");
message.setFrom("thymeleaf@example.com");
message.setTo(recipientEmail);
// Create the HTML body using Thymeleaf
final String htmlContent = this.templateEngine.process("email-simple.html", ctx);
message.setText(htmlContent /* isHtml */);
// Send email
System.out.println("........");
this.mailSender.send(mimeMessage);
}
Run Code Online (Sandbox Code Playgroud)
如果我删除使用thymeleaf创建html主体的行并发送普通邮件,它可以工作,但不能使用模板..
这是引起问题的线......只是重定向到错误页面
final String htmlContent …
Run Code Online (Sandbox Code Playgroud) 我的 Oracle 11g 数据库中有一个四列表,实现了扩展表反模式。我注意到有些查询花费了很长时间,并努力创建更好的索引;在交互式会话中效果很好,但使用 Spring\xe2\x80\x99s 仍然很慢NamedJdbcTemplate
。
考虑以下例程:
\n\nprivate void getObjectIds(ObjectDomain domain, HashMap<String, List<String>> dimensionMap)\n throws SQLException {\nString sql = "SELECT m2.OBJECT_ID"\n + " FROM MetaInformations m1, MetaInformations m2\\n"\n + " WHERE m1.OBJECT_ID = m2.OBJECT_ID\\n"\n + " AND m1.OBJECT_DOMAIN = :domain AND m1.KEY = :key1 AND\\n"\n + " m1.REF_OBJ_VALUE IN (:values1)\\n"\n + " AND m2.OBJECT_DOMAIN = :domain AND m2.KEY = :key2 AND\\n"\n + " m2.REF_OBJ_VALUE IN (:values2)";\nString sqlWithBind = "SELECT m2.OBJECT_ID\\n"\n + " FROM MetaInformations m1, MetaInformations …
Run Code Online (Sandbox Code Playgroud) 我使用Spring Boot。我想使用 YAML 而不是属性来编写配置。
由于我使用的spring-boot-starter
SnakeYAML 库已经在类路径中,并且 SpringApplication 应该自动使用 YAML 版本。
只要您的类路径上有 SnakeYAML 库,SpringApplication 类就会自动支持 YAML 作为属性的替代方案。
问题是应用程序继续使用 application.properties 文件,如果我删除它,则根本不会加载任何配置。
有人能帮我吗?这是我的主文件
@SpringBootApplication
public class App {
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(App.class);
app.setBannerMode(Banner.Mode.OFF);
app.run(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的pom.xml
....
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</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)
application.yml 文件只是
tasks: …
Run Code Online (Sandbox Code Playgroud) 我想使用Spring Boot 2(暂时构建快照)启动一个新项目,然后使用Spring Framework 5(也是前沿).原因是春季5应该有很多改进的Kotlin支持,我想使用Kotlin.
现在我发现的示例使用Spring Boot 1.4.3,当然还有Gradle,当然还有基于Kotlin的Gradle文件.说实话,对于一个项目来说,这对我来说是太多新技术.我甚至不知道如何在Gradle(Kotlin-Gradle!)构建脚本中添加新的存储库.我更喜欢Maven项目,因为我至少对它很熟悉,而全新的Spring和Kotlin将会有足够的实验.
那么,如何在Maven中做到这一点?kotlin-spring
我在Gradle中看到的插件是什么?
从Fabric文档create-join-channel,当我执行命令时
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Run Code Online (Sandbox Code Playgroud)
它会返回以下消息的错误代码段:
2017-08-16 01:34:13.902 UTC [msp] GetLocalMSP - > DEBU 00c返回现有的本地MSP 2017-08-16 01:34:13.902 UTC [msp] GetDefaultSigningIdentity - > DEBU 00d获取默认签名身份2017-08- 16 01:34:13.902 UTC [msp/identity]签名 - > DEBU 00e标志:明文:0AC3060A1508021A060895C2CECC0522 ... 7E2E59E3CFD14AC765C92FBF36614E79 2017-08-16 01:34:13.902 UTC [msp/identity]签名 - > DEBU 00f签名:摘要:FA75790826EF23E1A7C46AD3B9AE0DB7321DC271B8BE93A29BAC2F6EEACBB8B0错误:出现意外状态:BAD_REQUEST用法:对等通道创建[标志]
标志:
comamands如下:
cryptogen生成--config =./ crypto-config.yaml
export FABRIC_CFG_PATH = $ PWD
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
导出CHANNEL_NAME = mychannel
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $ CHANNEL_NAME
configtxgen …
考虑以下项目布局(假设A和B相互依赖):
.
|-- bin1
|-- bin2
|-- src1
| `-- A.java
`-- src2
`-- B.java
Run Code Online (Sandbox Code Playgroud)
编译后,我希望这些类驻留在各自的文件夹中:
.
|-- bin1
| `-- A.class
|-- bin2
| `-- B.class
|-- src1
| `-- A.java
`-- src2
`-- B.java
Run Code Online (Sandbox Code Playgroud)
从命令行可以很简单:
$ javac -implicit:none -sourcepath src1:src2 -d bin1 src1/*
$ javac -implicit:none -sourcepath src1:src2 -d bin2 src2/*
Run Code Online (Sandbox Code Playgroud)
如果这样配置,Eclipse也会这样做.但我无法弄清楚如何用Ant做到这一点.
附录:我目前的javac
任务:
<javac destdir="${classes.1.dir}">
<src path="${src.1.dir}" />
<src path="${src.2.dir}" />
</javac>
<javac destdir="${classes.2.dir}">
<classpath path="${classes.1.dir}" />
<src path="${src.2.dir}" />
</javac>
Run Code Online (Sandbox Code Playgroud)
注意循环依赖.在第二个任务的效果很好,它只是编译什么的src2 …
我厌倦了添加手动日志来调试我编写的每个方法。
我开始了解jcabi 的@Loggable
注释,但没有成功实施,非常感谢您的帮助。
下面是我尝试过的代码。
import com.jcabi.aspects.Loggable;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class Jcabi {
@Loggable
private static String checkJcabi(String stringToPrint) {
log.info("Print Successfull");
return stringToPrint;
}
public static void main(String[] args) {
checkJcabi("Hello World!");
}
}
Run Code Online (Sandbox Code Playgroud)
IDE 控制台打印:
[main] INFO com.amazon.optimus.cpamutil.utils.Jcabi - Print Successfull
Run Code Online (Sandbox Code Playgroud)
这是log.info()
我在方法中添加的日志,并且没有@Loggable
像这篇文章中提到的这样(下面)的注释日志
[INFO] com.example.Foo #power(2, 10): 1024 in 12?s
[INFO] com.example.Foo #power(3, 3): 27 in 4?s
Run Code Online (Sandbox Code Playgroud)
以下是我使用的依赖包:
JCabiAspects = 1.0;
方面J = 6.0;
Slf4j = 1.7;
Slf4j_Simple = 1.7; …