我正在尝试使用com.google.common.base.Splitter,如下所示
Iterable<String> segs = Splitter.on("/").split("one/two/three/four/five");
for (String seg : segs) {
  System.out.println(seg);
}
但是,我看到以下异常:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Platform.precomputeCharMatcher(Lcom/google/common/base/CharMatcher;)Lcom/google/common/base/CharMatcher;
    at com.google.common.base.CharMatcher.precomputed(CharMatcher.java:664)
    at com.google.common.base.CharMatcher.<clinit>(CharMatcher.java:71)
    at com.google.common.base.Splitter.<init>(Splitter.java:107)
    at com.google.common.base.Splitter.on(Splitter.java:171)
    at Test.main(Test.java:30)
有谁知道我在这里做错了什么?
我正在寻找一种生成字母序列的方法:
A, B, C, ..., Z, AA, AB, AC, ..., ZZ.
任何人都可以建议一种方便的方法.我可以使用哪些数据结构?
我想要获取序列中的下一个代码然后重置序列的方法.
我无法使用Java 11和最新版本的maven-compiler-plugin构建.
pom.xml中:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>
            </configuration>
        </plugin>
    <plugins>
<build>
当我尝试使用Maven构建时:
?  mvn clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 80 source files to /home/mip/service/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.859 s
[INFO] Finished at: 2018-08-01T11:20:55+01:00
[INFO] Final Memory: 32M/124M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to …将应用程序部署到GlassFish时,我看到以下警告:
WARN  AnnotationTypeConverterLoader  - Ignoring converter type: org.apache.activemq.camel.converter.ActiveMQMessageConverter as a dependent class could not be found: java.lang.NoClassDefFoundError: org/apache/camel/Processor java.lang.NoClassDefFoundError: org/apache/camel/Processor
该应用程序似乎按预期工作,但这个警告让我烦恼.我的POM中有以下内容:
    <properties>
         <camel-version>2.13.2</camel-version>
    </properties>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-aws</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jsonpath</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-sql</artifactId>
        <version>${camel-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-jms</artifactId>
        <version>${camel-version}</version>
    </dependency>
有谁知道可能导致此警告的原因?
这是完整的堆栈跟踪:
[2014-09-18T16:10:46.762+0100] [glassfish 4.0] [INFO] [] [] [tid: _ThreadID=65 _ThreadName=Thread-13] [timeMillis: 1411053046762] [levelValue: 800] [[
  2014-09-18 16:10:46,760 [min-listener(5)] WARN  AnnotationTypeConverterLoader …谁能为我提供一些关于实现这一目标的最佳方法的指导。
我想扩展 Spring Boot外部化配置,以便我有一个可以从应用程序中的任何位置调用的方法。此方法将使用键检索属性值。此方法将首先询问数据库表,如果没有找到指定的键,则将退回到1中描述的 PropertySource 顺序。
所以我会有类似的服务:
@Service
public class ConfigurationService {
    private final ConfigurationRepository configurationRepository;
    @Autowired
    public ConfigurationService(ConfigurationRepository configurationRepository) {
        this.configurationRepository = configurationRepository;
    }
    public String getValue(String key) {
        Configuration configuration = configurationRepository.findOne(key);
        // Add something here to get the property from application.properties if the key does not exist in the db
        return configuration == null ? null : configuration.getValue();
    }
}
我可以使用如下:
foo = configuration.getValue("my.property");
有更好的方法来解决这个问题吗?我是否缺少可以利用的 Spring Boot 功能?
我希望能够在应用程序运行时更改属性的值并获取这些新值。
我目前在我的手中有以下内容application.properties:
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
该文件的实际路径是src/main/resources/db/changelog/db.changelog-master.xml.
更改日志是由Liquibase发现的,一切都按照我的预期运作.
我已将更改日志和项目的所有JPA实体和存储库移动到一个单独的项目中,以便可以与其他项目共享.
第二个项目是第一个项目的Maven依赖项.我需要在application.properties第一个项目中使用哪条路径来访问第二个项目中的liquibase changelog?
更新
我有:
projectA.jar - > pom.xml
<dependency>
    <groupId>com.foo</groupId>
    <artifactId>projectB</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
projectA.jar - > application.properties
liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
projectB.jar - > src/main/resources/db/changelog/db.changelog-master.xml
但是我得到了:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration$LiquibaseConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find changelog location: class path resource [db/changelog/db.changelog-master.xml] (please add changelog or check your Liquibase configuration)
我正在尝试设置我的单元测试环境以使用DbUnit.
我遇到了一些问题,因为我试图控制的表没有主键.我得到了一个org.dbunit.dataset.NoPrimaryKeyException.
我按照这里的步骤http://dbunit.wikidot.com/noprimarykeytable但我该如何使用:
connection.getConfig().setProperty("http://www.dbunit.org/properties/primaryKeyFilter", new MyPrimaryKeyFilter("A1"));
对于我的每张桌子?
例如,我有以下数据库:
CREATE TABLE `NO_PK1` (
  `A1` int(11) NOT NULL,
  `A2` varchar(50) default NULL
);
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
  <NO_PK1 A1="1" A2="Test1" />
  <NO_PK1 A1="2" A2="Test2" />
  <NO_PK1 A1="3" />
</dataset>
CREATE TABLE `NO_PK2` (
  `B1` int(11) NOT NULL,
  `B2` varchar(50) default NULL
);
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
  <NO_PK2 B1="1" B2="Test1" />
  <NO_PK2 B1="2" B2="Test2" />
  <NO_PK2 B1="3" />
</dataset>
CREATE TABLE `NO_PK3` (
  `C1` int(11) NOT NULL,
  `C2` varchar(50) …我正在尝试向Axis 1.4 Web服务器添加自定义HTTP标头.
我创建了一个扩展BasicHandler的处理程序:
public class HttpHeaderHandler extends BasicHandler {
  .
  .
  .
  @Override
  public void invoke(org.apache.axis.MessageContext arg0) throws AxisFault {  
    LOG.trace("invoke called");     
    Hashtable ht = (Hashtable)ctx.getProperty(HTTPConstants.RESPONSE_HEADERS);
    if(ht == null) {
      ht = new Hashtable();
    }
    ht.put("custom-header", "Hello");
    ctx.setProperty(HTTPConstants.RESPONSE_HEADERS, ht);     
  }
  .
  .
  .
}
我已将以下内容添加到server-config.wsdd:
    .
    .
    .
<transport name="http">
    <requestFlow>
        <handler type="URLMapper" />
        <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
    </requestFlow>
    <responseFlow>
        <handler type="java:com.my.package.HttpHeaderHandler" />
    </responseFlow>
</transport>
    .
    .
    .
我可以看到正在调用invoke方法,因为日志文件出现在日志文件中,但自定义标头未添加到响应中.
任何建议赞赏.
我的代码被部署为JAR文件.JAR包含一个目录lib,其中包含我的代码所需的许多第三方JAR.我已经classpath使用Ant,通过它添加了这些MANIFEST.MF.
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 20.5-b03 (Sun Microsystems Inc.)
Main-Class: com.package.Class
Class-Path: ../lib/c3p0-0.9.1.2.jar ../lib/dbunit-2.4.8.jar ../lib/gua
va-10.0.1.jar ../lib/hsqldb.jar ../lib/javax.jms.jar ../lib/log4j-1.2
 .16.jar ../lib/mockito-all-1.9.0.jar ../lib/ojdbc14.jar ../lib/slf4j-
 api-1.6.4.jar ../lib/slf4j-log4j12-1.6.4.jar ../lib/xmlunit-1.3.jar
还有一个queries.properties文件位于JAR的根目录中.
还有两个属性文件是必需的.我希望这些驻留在与JAR文件相同的目录中,并使代码能够找到它们.我相信代码能够找到这些属性文件,它们需要在classpath.因此,我需要将JAR文件的目录添加到classpath.
首先,这是正确的方法,我应该使用另一种方法来定位属性文件?
如果这是正确的,我如何使用Ant将JAR的当前目录添加到类路径中MANIFEST.MF?我在lib目录中添加了classpath使用manifestclasspathAnt任务的JAR .
我有
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
在我的 pom.xml 中,因此我的 Spring Boot 应用程序在启动时尝试连接到本地主机上的 MongoDB。
我也有
<dependency>
  <groupId>de.flapdoodle.embed</groupId>
  <artifactId>de.flapdoodle.embed.mongo</artifactId>
  <scope>test</scope>
</dependency>
因此,当我运行单元测试时,会使用嵌入式 MongoDb。
出于集成测试的目的,如果应用程序是使用“测试”活动配置文件启动的,我还想使用嵌入式 MongoDB。
因此,我想有效地删除<scope>test</scope>嵌入依赖项,并在活动配置文件为“测试”时使用嵌入版本。
我怎样才能实现这个目标?
我有以下代码,它使用了Guava的Files.readLines()方法:
List<String> strings = Lists.newArrayList();
final File file = new File(filePath);
if (file.isFile()) {
  try {
    strings= Files.readLines(file, Charsets.UTF_8);
  }
  catch (IOException ioe) {}
}
else {
  // File does not exist
}
一旦我有了我的String列表,我想测试一下,看看我正在查看的当前字符串是否在文件中.
String myString = "foo";
if (strings.contains(myString)) {
  // Do something
}
但是,我想使容忍原始文件的代码包含前导或尾随空格(即" foo ").
实现这一目标的最优雅方式是什么?
java ×10
guava ×3
spring ×3
spring-boot ×3
maven ×2
alphabetical ×1
ant ×1
apache-camel ×1
axis ×1
classpath ×1
collections ×1
dbunit ×1
deployment ×1
file-io ×1
glassfish ×1
java-11 ×1
jax-rpc ×1
junit ×1
linux ×1
liquibase ×1
mongodb ×1
properties ×1
sequence ×1
splitter ×1
string ×1
ubuntu ×1
web-services ×1