小编zig*_*ggy的帖子

配置 Spring 以在 bean 初始化之前设置系统属性

在 Spring MVC Web 应用程序中,我在配置文件中配置了一个 bean:

<bean class="com.callback.CallbackService"/>
Run Code Online (Sandbox Code Playgroud)

在服务类中,bean 被初始化如下:

@Autowired
CallbackService service
Run Code Online (Sandbox Code Playgroud)

上面显示的 CallbackService 通过进行以下三个调用来获取其连接属性(目前无法更改):

System.getProperty("user");
System.getProperty("password");
System.getProperty("connectionURL");
Run Code Online (Sandbox Code Playgroud)

声明 CallbackService 实例的服务类可以通过读取属性文件来访问上述三个值,如下所示:

@Value("${user}")
protected String userName;

@Value("${password}")
protected String password;

@Value("${connection}")
protected String connectionString;  
Run Code Online (Sandbox Code Playgroud)

为 CallbackService 设置属性所需的只是设置系统属性(在它们初始化之后),如下所示:

System.setProperty("user", userName);
System.setProperty("password", password);
System.setProperty("connectionURL", connectionString);
Run Code Online (Sandbox Code Playgroud)

然而,我遇到的问题是对象初始化的顺序。属性正在初始化,但看起来 System.setProperty 调用发生在 Spring 从属性文件中准备好它们之前。

我尝试了几种解决方案,但似乎 CallbackService 对象在从属性文件中读取值并调用 System.setProperty 之前实例化。

最终会读取属性文件,因为如果我从 @Controller 方法之一访问它们,我可以看到这些值。问题在于初始化属性和初始化 CallbackService 实例的点。

经过几个小时的谷歌搜索,我尝试了以下解决方案,但似乎没有一个在 CallbackService 实例的初始化/实例化之前填充系统属性

  1. InitiazingBeanafterPropertiesSet()方法中实现和设置系统属性 。
  2. ApplicationListeneronApplicationEvent()方法中实现和设置系统属性。
  3. lazy-init=trueXML 中 CallbackService bean 定义的设置。
  4. 按照此处所述设置系统属性 使用 Spring …

java configuration spring spring-mvc jakarta-ee

5
推荐指数
1
解决办法
3万
查看次数

Swing - 是否可以在JTable单元格中设置"特定"文本的字体颜色?

我有一个JTable,其中一列显示以下格式的值:

423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
Run Code Online (Sandbox Code Playgroud)

我想知道是否可以在RED中的方括号内显示值?

我最近几天一直在谷歌上搜索,并找到了几个例子来说明如何设置单元格的"背景",但实际上并不是如何更改单元格的字体,尤其是文本的特定部分.

public class myTableCellRenderer
       extends DefaultTableCellRenderer {
  public Component getTableCellRendererComponent(JTable table,
                                                 Object value,
                                                 boolean isSelected,
                                                 boolean hasFocus,
                                                 int row,
                                                 int column) {
    Component c = 
      super.getTableCellRendererComponent(table, value,
                                          isSelected, hasFocus,
                                          row, column);

    if (column == 3) {
       c.setForeground(Color.YELLOW);
       c.setBackground(Color.RED);
    }
    return c;
  }
Run Code Online (Sandbox Code Playgroud)

是否真的可以将文本的一部分更改为不同的颜色(即方括号内的文本).

编辑

我作为示例显示的文本是表格单元格中显示的实际文本(逗号分隔符不表示列).单元格中显示的文本是逗号分隔的字符串,我在第3列的表格中显示.

作为一个例子,表格看起来像这样

product_id |product_name| invoice_numbers
12         |    Books   | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
323        |    Videos  | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
4434       |    Music   | 423545(50),[7568787(50)],53654656,2021947(50),[021947],2021947(50),[8021947(50)]
Run Code Online (Sandbox Code Playgroud)

java user-interface fonts swing awt

5
推荐指数
2
解决办法
8122
查看次数

sql join - 加入多个表

我试图理解连接,我有点困惑.我知道如何使用连接表

=
<=
Run Code Online (Sandbox Code Playgroud)

IN存在且不存在

我试图尝试理解INNER JOIN,LEFT OUTER JOIN,USING等的使用,但它太令人困惑了.我遇到的主要问题是不同的人使用不同的名称来引用它们.是否有一个关于不同类型的连接的简单解释以及它们所知的其他名称.例如,谷歌搜索我遇到以下类型

? Simple Join
? Equi join
? Natural Join
? Outer Join
? Self Join
? Cartesian join
? Inner join
? Nonequi join
? Theta join
? Self join 
? Cross join
? Cross Joins
? Natural Joins
? Inner Join with USING Clause
? Inner Join with ON Clause
? Left Outer Join
? Right Outer Join
? Full OuterJoin
Run Code Online (Sandbox Code Playgroud)

以上大部分都是重复的,即它的连接类型相同但名称不同.我相信所有上述内容都可以使用(=,!=,not in,in exists等)中的一个来重新创建,但我正在努力解决哪个是哪个以及它们之间的区别.图表可能有帮助:)

sql oracle join inner-join left-join

4
推荐指数
1
解决办法
2248
查看次数

JIRA开源许可证

我在Jira网站上的许可信息部分看到了这一点

JIRA is free for use by official non-profit organisations and charities (proof of     non-profit status is required). There are certain organisations whose purpose is to make the world a better place, and we believe in helping them achieve that.

Community licenses are designed for organisations which are:

    * non-profit,
    * non-government,
    * non-academic,
    * non-commercial,
    * non-political and
    * secular
Run Code Online (Sandbox Code Playgroud)

最后一个要点究竟是什么意思?这是否意味着,如果你相信上帝,你就无法获得bug跟踪软件产品的免费许可?

licensing jira

4
推荐指数
2
解决办法
1284
查看次数

如何在Java中正确创建制表符分隔的文本文件

我正在尝试创建一个tab delimeted文本文件,以便输出显示为列,但由于某种原因,选项卡显示在不同的位置.这是由数据值不同的事实引起的.

这是我如何构建行和列

output.append("|\t" + column1 + "\t\t\t:\t" + column2 +"  \t\t\n");
Run Code Online (Sandbox Code Playgroud)

输出结果如下

|   activeSessions      : 0         
|   duplicates      : 0         
|   expiredSessions         : 0         
|   rejectedSessions        : 0         
|   sessionMaxAliveTime         : 0         
|   sessionCounter      : 0         
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,第一列上包含较长文本条目的值会导致第二列稍微移动一点,即使两列都由两个选项卡分隔.如何确保第二列位置在同一行?

谢谢

java formatting text string-formatting

4
推荐指数
2
解决办法
2万
查看次数

NumberFormat解析货币值失败

使用Number格式的Currency实例进行语法分析时,为什么以下生成解析异常.

    float f1    =   123.45678f;
    Locale  locFR   =   new Locale("fr");
    NumberFormat[] nfa  =   new NumberFormat[4];

    nfa[0]  =   NumberFormat.getInstance(); //default
    nfa[1]  =   NumberFormat.getInstance(locFR);    //FranceLocale
    nfa[2]  =   NumberFormat.getCurrencyInstance(); //Default Currency
    nfa[3]  =   NumberFormat.getCurrencyInstance(locFR); //French Currency

    for (NumberFormat nf : nfa){

        System.out.println("----------- " +  nf.getClass().getName() + "-----------------------");
        System.out.println("Default maximum fraction digits : " + nf.getMaximumFractionDigits());
        System.out.println(nf.format(f1));

        nf.setMaximumFractionDigits(5);
        System.out.println("Maximum fraction digits updated to : " + nf.getMaximumFractionDigits());
        System.out.println(nf.format(f1));

        try{
            nf.setMaximumFractionDigits(5);
            System.out.println("parsed string: " + nf.parse("1234.56732"));
            nf.setParseIntegerOnly(true);
            System.out.println("after setParseIntegerOnly" + nf.parse("1234.567"));
        }catch (Exception e){e.printStackTrace();}; 
Run Code Online (Sandbox Code Playgroud)

以上的输出是 …

java string formatting datetime text

4
推荐指数
1
解决办法
8072
查看次数

Arrays.BinarySearch是否要求数组按升序排序

根据文件:

public static <T> int binarySearch(T[] a, T key, Comparator<? super T> c)        
Run Code Online (Sandbox Code Playgroud)

使用二进制搜索算法在指定的数组中搜索指定的对象.

在进行此调用之前,必须根据指定的比较器(通过sort(T [],Comparator)方法)将数组按升序排序.

如果未排序,则结果未定义.如果数组包含多个与指定对象相等的元素,则无法保证找到哪个元素.

以上是否意味着该Arrays.binarySearch方法只能在Array按升序排序时使用?

我测试了它,如下所示

class Unturned {
    public static void main(String[] args) {
        String[] chars = {"a", "b", "c", "e","f","h","i"};
        MySort ms = new MySort();

        Arrays.sort(chars, ms);
        for(String c : chars ) System.out.print(c + " ");

        System.out.println("\n" + Arrays.binarySearch(chars, "d", ms));
    }
    static class MySort implements Comparator<String> {
        public int compare(String a, String b) {
            return b.compareTo(a);
} } }
Run Code Online (Sandbox Code Playgroud)

输出: …

java oop string scjp

4
推荐指数
1
解决办法
9625
查看次数

Maven jaxb生成插件以从多个目录中读取xsd文件

如果我在以下目录中有xsd文件

src/main/resources/xsd
src/main/resources/schema/common
src/main/resources/schema/soap
Run Code Online (Sandbox Code Playgroud)

我如何指示maven jaxb插件使用上面目录中的所有模式文件生成jaxb类?我可以让它生成类文件,如果我指定其中一个文件夹但我不能得到我不知道如何包括所有三个文件夹.

以下是我为一个文件夹生成文件的方法:

<plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <schemaDirectory>src/main/resources/xsd</schemaDirectory>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我尝试在元素中添加多个条目,但如果我这样做,它就会忽略所有条目.

谢谢

java xsd jaxb maven

4
推荐指数
1
解决办法
1万
查看次数

泽西岛客户服务 - 关闭资源

我有一个服务类,它有许多方法可以对Spring REST服务进行REST调用.每个方法看起来像这样:

public void getUser() {

        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        WebResource service = client.resource(RESOURCE_URL);


        // Get response as String
        String response = service.path("/addUser").accept(MediaType.TEXT_PLAIN)
                .get(String.class);

        return response;
    }
Run Code Online (Sandbox Code Playgroud)

以上工作正常,但我有点担心每次调用该方法时,都会创建ClientConfig,Client和WebResource的新实例.改变上述内容并将ClientConfig,Client和WebResource作为类级实例变量的副作用是什么?即改为:

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(RESOURCE_URL);

public void getUser() {         

        // Get response as String
        String response = service.path("/addUser").accept(MediaType.TEXT_PLAIN)
                .get(String.class);

        return response;
    }

 public void getUserAccount() {         

        // Get response as String
        String response = service.path("/getUserAccount").accept(MediaType.TEXT_PLAIN)
                .get(String.class);

        return response;
    } …
Run Code Online (Sandbox Code Playgroud)

java rest spring jersey java-ee

4
推荐指数
1
解决办法
6220
查看次数

Java - 从混合了 UTF-8 和非 UTF-8 字符的字符串中精确计算 60 个字符

我有一个字符串,我想将其保存在仅支持 UTF8 字符的数据库中。如果字符串大小 > 60 个字符,我想截断它并只存储前 60 个字符。使用中的 Oracle 数据库仅支持 UTF-8 字符。

String.substring(0,59)在 Java 中使用返回 60 个字符,但是当我将它保存在数据库中时,它被拒绝,因为数据库声称该字符串 > 60 个字符。

  • 有没有办法找出特定字符串是否包含非 UTF8 字符。我发现的一种选择是:

    try {

        bytes = returnString.getBytes("UTF-8");
    
    
    } catch (UnsupportedEncodingException e) {
        // Do something
    
    Run Code Online (Sandbox Code Playgroud)

    }

  • 有没有办法可以将它截断为正好 x 个字符(数据丢失不是问题),并确保在数据库中保存时只保存 x 个字符。例如,如果我有字符串§8§8§8§8§8§8§8,我说截断并只保存 5 个字符,它应该只保存§8§

java string oracle encoding character-encoding

4
推荐指数
1
解决办法
1034
查看次数