我在 macOS Mojave 10.14.5 上使用带有 Kotlin(kotlinc-jvm 1.3.31)的 IntelliJ IDEA 2019.1.2(终极版)。
当我创建了一个 Kotlin JVM 项目并添加了一个名为“Nullability.kt”的 Kotlin 文件时,代码如下(带有 main() 方法的扩展函数):
fun List<Int>.allNonZero() = all { it > 0 }
fun main() {
val list1 = listOf(1, 2, 3)
list1.allNonZero() eq true
}
Run Code Online (Sandbox Code Playgroud)
IntelliJ IDEA 以红色突出显示“eq”,并指出:
Kotlin: Unresolved reference: eq
Run Code Online (Sandbox Code Playgroud)
如何从 IntelliJ IDEA 中解决这个问题?
我试图使用Log4j写入我的文件系统中的本地日志文件.
实际上使用了来自不同项目的确切属性文件,只是更改了顶级目录的名称以匹配我的应用程序名称.不同的项目写入logs.log文件,但这根本不打印任何内容.两个项目都使用相同版本的log4j.
的pom.xml
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在我的基于Unix的macOS上,我进入/ var/log /并执行以下操作:
sudo mkdir myapp
chmod 777 myapp
Run Code Online (Sandbox Code Playgroud)
在myapp内部,以下设置遍布整个地方:
if (log.isDebugEnabled() {
log.debug("print something");
}
Run Code Online (Sandbox Code Playgroud)
MYAPP/src目录/主/资源/ log4j.properties:
log4j.rootCategory=DEBUG, RF
log4j.category.your.category.name=DEBUG
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%F]: %m [%d{ISO8601}]%n
log4j.logger.com.amazonaws=DEBUG RF
log4j.appender.RF=org.apache.log4j.RollingFileAppender
log4j.appender.RF.File=/var/log/myapp/logs.log
log4j.appender.RF.MaxFileSize=10MB
log4j.appender.RF.MaxBackupIndex=30
log4j.appender.RF.layout=org.apache.log4j.PatternLayout
log4j.appender.RF.layout.ConversionPattern=[%d{ISO8601}]%5p%6.6r[%t]%x(%F:%L) - %m%n
Threshold=DEBUG
Run Code Online (Sandbox Code Playgroud)
不明白为什么在里面:
/var/log/myapp/
Run Code Online (Sandbox Code Playgroud)
没有logs.log文件!
我在使用以下构建的Spring Boot 1.5.4.RELEASE中使用它:
mvn clean install
Run Code Online (Sandbox Code Playgroud)
然后运行使用:
java -jar myapp.jar
Run Code Online (Sandbox Code Playgroud)
要么
mvn spring-boot:run
Run Code Online (Sandbox Code Playgroud)
如果有人能为我提供更好的属性文件或看到我做错了什么,我将不胜感激?
感谢您抽出时间来阅读.
似乎不知道在我的WebService类中正确使用wsgen的位置(什么目录 - 源或类)...
创建基于WebService的示例文档文字:
package hello;
import javax.jws.WebService;
@WebService
public class HelloWorld {
public void sayHello() {
System.out.println("Welcome to JAX-WS 2!");
}
}
Run Code Online (Sandbox Code Playgroud)
像这样创建了发布者:
package hello;
import javax.xml.ws.Endpoint;
public class Publisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/jaxws/hello", new HelloWorld());
}
}
Run Code Online (Sandbox Code Playgroud)
使用Eclipse Helios,我自动将这两个文件构建为相应类目录下的*.classes.
所以,从文件系统来看,我的项目看起来像这样:
/code/jws_sample
|
src
|
hello
|
HelloWorld.java
Publisher.java
|
classes
|
HelloWorld.class
Publisher.class
Run Code Online (Sandbox Code Playgroud)
我会在哪个目录中运行wsgen?
当我在里面尝试时:
/ code/jaxws_sample/src/wsgen -cp.hello.HelloWorld
收稿日期:
Class not found: "hello.HelloWorld"
Usage: WSGEN [options] <SEI>
where [options] include:
-classpath <path> specify where …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Spring Boot 应用程序内的 JUnit 访问 application.properties 或 application-test.properties 。
\n\n我不断在 Stack Overflow 上看到不同的方法来执行此操作,并且只想使用我的 AppConfig 类(见下文)。
\n\n我正在使用 Spring Boot 1.5.6 RELEASE 和 Java 1.8
\n\n这是我的应用程序的结构:
\n\nMyService\n pom.xml\n src\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80main\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80com\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80myservice\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80config\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 AppConfig.java\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80controller\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 UserController.java\n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 \n \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 MyServiceApplication.java \n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80resources\n \xe2\x94\x82 \xe2\x94\x82 application.properties\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80test\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80java\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80com\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80myservice\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80controller\n \xe2\x94\x82 UserControllerTest.java\n …
Run Code Online (Sandbox Code Playgroud) 使用 Spring Boot 2.1.5 Release,创建了以下示例 Spring Boot 微服务:
Maven项目结构:
MicroService
?
pom.xml
src
?
????main
?
????java
? ?
? ????com
? ????microservice
? ?
? ????MicroServiceApplication.java
?
????resources
?
????data.json
?
application.properties
Run Code Online (Sandbox Code Playgroud)
有以下 JSON 文件(在 src/main/resources/data.json 中):
{"firstName": "John", "lastName": "Doe"}
Run Code Online (Sandbox Code Playgroud)
微服务应用:
@SpringBootApplication
public class MicroServiceApplication {
@Bean
CommandLineRunner runner() {
return args -> {
String data = FilePathUtils.readFileToString("../src/main/resources/data.json", MicroServiceApplication.class);
System.out.println(data);
};
}
public static void main(String[] args) {
SpringApplication.run(MicroServiceApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
抛出以下异常:
java.lang.IllegalStateException: Failed to execute CommandLineRunner …
Run Code Online (Sandbox Code Playgroud) <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.cloudst</groupId>
<artifactId>cloudst</artifactId>
<version>0.1.2</version>
<packaging>jar</packaging>
<name>cloudst</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>com.springsource.repository.bundles.release</id>
<url>http://repository.springsource.com/maven/bundles/release/</url>
</repository>
<repository>
<id>EclipseLink</id>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
</repository>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.kitchen-eel</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${kitchen-eel.version}</version>
</dependency>
<build>
<finalName>cloudst</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
能够使用标准mvn命令从命令行成功清理,编译和安装此项目...
但是,在Eclipse Juno的"问题"窗格中,我有以下2个错误:
缺少工件org.kitchen-eel:json-schema-validator:jar:1.2.1 pom.xml /com.cloudst line 45 Maven依赖问题
ArtifactTransferException:无法传输org.kitchen-eel:json-schema-validator:jar:1.2.1
来自http://repo.maven.apache.org/maven2的缓存在本地存储库中,在中心的更新间隔过去或强制更新之前,不会重新尝试解析.原始错误:无法传输工件org.kitchen-eel:json-schema-validator:jar:1.2.1 from/to central(http://repo.maven.apache.org/maven2):
为什么它在命令行中工作但m2eclipse发布了问题?
感谢您抽时间阅读...
这是我之前发布的解决方案的后续跟进:
使用Elastic Search 5.5.0获得最佳性能时如何正确关闭原始RestClient?
同样的错误信息又回来了!
2017-09-29 18:50:22.497 ERROR 11099 --- [8080-Acceptor-0] org.apache.tomcat.util.net.NioEndpoint : Socket accept failed
java.io.IOException: Too many open files
at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) ~[na:1.8.0_141]
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:422) ~[na:1.8.0_141]
at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:250) ~[na:1.8.0_141]
at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:453) ~[tomcat-embed-core-8.5.15.jar!/:8.5.15]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_141]
2017-09-29 18:50:23.885 INFO 11099 --- [Thread-3] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5387f9e0: startup date [Wed Sep 27 03:14:35 UTC 2017]; root of context hierarchy
2017-09-29 18:50:23.890 INFO 11099 --- [Thread-3] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647
2017-09-29 18:50:23.891 WARN 11099 --- [Thread-3] o.s.c.support.DefaultLifecycleProcessor : …
Run Code Online (Sandbox Code Playgroud) 尝试在 Java 中创建一个方法,通过根据长度拉伸缓冲区的内容(通过放置适当数量的空格)来格式化字符串。因此,根据给定的特定长度,字符串的第一个字符位于第一个索引中,最后一个字符位于实际的最后一个索引本身。
public static String format(String sentence, int length) {
if (sentence.length() >= length) {
return sentence;
}
StringBuilder sb = new StringBuilder();
String[] words = sentence.split("\\s+");
int usedCharacters = 0;
for (String word : words) {
usedCharacters += word.length();
}
int emptyCharacters = length - usedCharacters;
int spaces = emptyCharacters / words.length - 1;
for (String word : words) {
sb.append(word);
for (int i = 0; i <= spaces; i++) {
sb.append(" ");
}
}
return sb.toString();
} …
Run Code Online (Sandbox Code Playgroud) 我尝试使用 Spring Secruity 的 OAuth API 从基于 Spring MVC 4 的 Web 服务(不是 Spring Boot)中外部发布的 API 获取访问令牌。
这个curl命令有效(它的内容是我获取访问令牌所需的全部内容):
curl -X POST \
https://api.app.com/v1/oauth/token \
-H 'content-type: application/x-www-form-urlencoded' \
-d'grant_type=client_credentials&client_id=bcfrtew123&client_secret=Y67493012'
Run Code Online (Sandbox Code Playgroud)
Spring Security OAuth API:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我获取访问令牌的代码:
@RequestMapping(value = "/getAccessToken", method = RequestMethod.POST, consumes="application/x-www-form-urlencoded")
public OAuth2AccessToken getAccessToken(@RequestParam(value="client_id", required=true) String clientId, @RequestParam(value="client_secret", required=true) String clientSecret) throws Exception {
String tokenUri = "https://api.app.com/v1/oauth/token";
ResourceOwnerPasswordResourceDetails resourceDetails = new ResourceOwnerPasswordResourceDetails();
resourceDetails.setAccessTokenUri(tokenUri);
resourceDetails.setClientId(clientId);
resourceDetails.setClientSecret(clientSecret);
resourceDetails.setGrantType("client_credentials");
resourceDetails.setScope(Arrays.asList("read", "write"));
DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
oauth2RestTemplate …
Run Code Online (Sandbox Code Playgroud) 使用 PlantUML 生成包含图例和页脚创建了一个序列图。
页脚包含我公司的名称和版权日期。
图例非常接近页脚,我需要在图例和页脚之间插入一个新行(或 a<br>
或 a )。<p>
另外,我的标题似乎在标题和图例之间有很大的空间。
我的 puml DSL 文件:
@startuml
skinparam Shadowing false
title __Dating API Sequence Diagram__\n
caption \nVersion 1.0 - 6/26/2020 (Draft)\n
autonumber
activate DatingApp
DatingApp -> DatingRestController: hitExternalApi()
activate DatingRestController
DatingRestController -> DatingService: processService()
activate DatingService
DatingService -> DatingService: findProfile()
activate DatingService #90EE90
DatingService -> DatingService: doSomething()
DatingService -> DatingService: doSomethingElse()
deactivate DatingService
DatingService -> DatingRestController: return retValue
DatingRestController -> DatingApp: jsonPayload
deactivate DatingRestController
deactivate DatingApp
legend bottom right
Legend …
Run Code Online (Sandbox Code Playgroud)