小编Ana*_*dhi的帖子

是Spring MVC控制器单身人士吗?

我对Spring 3 MVC有疑问 @Controllers.当请求进来时,容器是否为每个请求创建一个新的控制器实例(类似于Struts 2中的Action - ThreadLocal ActionContext)或单个实例响应所有请求?默认情况下,上下文中的控制器bean单例?

Spring 3 MVC应用程序的准则/最佳实践是什么?这些设置是否可配置?应该配置?如果我的环境是一个集群环境,它会有多大变化 - 我想它不应该因为jvm /容器会有所不同 - 但是一些权威的建议会受到欢迎.

我读过Spring文档,但可能我错过了它.任何'这就是我们如何实现'答案/指针/链接将是有用的谢谢.

java spring spring-mvc

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

在 JUnit 测试用例中的 @ContextConfiguration 中指定类加载顺序

我使用 junit 4.11 和 spring-test-4.1.5 来编写集成测试用例。我正在使用 @ContextConfiguration 注释来加载配置,例如,

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes ={ApplicationConfig.class,SpringConfiguration.class }, initializers = {CustomProfileResolver.class, AppInitializer.class}, loader = SpringApplicationContextLoader.class)
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在使用两个配置类。我面临的问题是我想加载SpringConfiguration.class之前的 ApplicationConfig.class。我尝试颠倒顺序,但没有成功。此处不能指定@order。

那么如何顺序加载这些配置类呢,可以吗?

java junit spring spring-test

9
推荐指数
1
解决办法
9743
查看次数

为什么在使用Spring Redis时收到JedisConnection的NoClassDefFound错误

您好,当我尝试使用spring-redis时

java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.redis.connection.jedis.JedisConnection
Run Code Online (Sandbox Code Playgroud)

使用Redis进行任何连接操作时发生异常。我的配置方法是这样的

 @Bean
public RedisConnectionFactory jedisConnFactory() {
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();

    jedisConnectionFactory.setHostName("XXX.XX.XX.XXX");

    jedisConnectionFactory.setPort(6381);
    jedisConnectionFactory.setUsePool(true);
    jedisConnectionFactory.afterPropertiesSet();
    return jedisConnectionFactory;
Run Code Online (Sandbox Code Playgroud)

请提出建议,如果有人知道我为什么收到此例外。

java spring redis

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

从HttpMessageNotReadable异常中获取路径变量

我们有一些移动客户端正在使用的Web服务,其中移动客户端发出一些请求并返回响应.不知何故,如果客户端发出任何无效请求,我们会抛出Custom Exceptions.
但最近移动客户端提出了一些超出范围Long变量的请求.
客户端有不同的变量为ex ::

    {
      "accountId":"343"
      "Amount":"90909090909090909090"
    }
Run Code Online (Sandbox Code Playgroud)

如果accountId或Amount的值超过19位,我们会得到HttpMessageNotReadable异常,因为范围超出了long值.但是从异常中我无法获取异常被提出的变量,无论是for accountId还是Amount.从异常我得到的信息_path变量,但我无法获取它. 在此输入图像描述

在路径变量我得到像::

[com.Upload["AccountInfo"], com.Info["Account"]]
Run Code Online (Sandbox Code Playgroud)

有人知道如何获取这些信息.

java variables spring path httpexception

6
推荐指数
1
解决办法
652
查看次数

RollingFile Appender Log4j2 不打印行号

我正在使用 log4j2 并具有以下依赖项::

   <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0-rc1</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下配置::

    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">

    <Properties>
        <Property name="LOGGER_HOME">/logs</Property>
    </Properties>

    <Appenders>

        <RollingFile name="application" fileName="${LOGGER_HOME}/application.log"
            filePattern="${LOGGER_HOME}/application.%d{yyyy-MM-dd}_%i.log">

            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="1 GB" />
            </Policies>

        </RollingFile>

        <RollingFile name="framework" fileName="${LOGGER_HOME}/em-logs/framework.log"
            filePattern="${LOGGER_HOME}/framework.%d{yyyy-MM-dd}_%i.log">

            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="1 GB" />
            </Policies>
        </RollingFile>

        <Console name="out" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{ISO8601}{GMT} %-5p %C{2} (%F:%L) - %m%n" />
        </Console>

        <Async name="asyncApplication"> …
Run Code Online (Sandbox Code Playgroud)

logging rollingfileappender line-numbers pattern-layout log4j2

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

JBoss standalone.xml 文件更改被覆盖

我们在我们的项目中使用 JBoss 7 并在standalone.xml文件中编写了这样的日志配置,

 <subsystem xmlns="urn:jboss:domain:logging:1.0">
        .
        .
        .
        <logger category="com.xyz.abc.aspect">
            <level name="DEBUG"/> 
            <handlers>
                <handler name="FILE"/>
            </handlers>
        </logger>
        .
        .
    </subsystem>
Run Code Online (Sandbox Code Playgroud)

现在出现了一种情况,我想通过添加来更改日志配置use-parent-handlers="false"以避免日志被重定向到父处理程序,现在当我将其添加到 standalone.xml 时

 <logger category="com.xyz.abc.aspect" use-parent-handlers="false">
                <level name="DEBUG"/> 
                <handlers>
                    <handler name="FILE"/>
                </handlers>
            </logger>
Run Code Online (Sandbox Code Playgroud)

并重新启动服务器,日志配置被 JBoss 恢复到以前的状态,即

<logger category="com.xyz.abc.aspect">
                <level name="DEBUG"/> 
                <handlers>
                    <handler name="FILE"/>
                </handlers>
            </logger>
Run Code Online (Sandbox Code Playgroud)

我试过删除standalone_xml_history目录和它下面的文件,但没有什么能阻止覆盖行为,任何人都可以提出建议。

java xml logging jboss

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

日志存放位置ELK栈

我正在使用 logstash 进行集中式日志记录。我在托运人节点上使用 logstash-forwarder,在收集器节点上使用 ELK 堆栈。我想知道日志存储在 elasticsearch 中的位置,我没有看到在存储日志的位置创建了任何数据文件。有人知道吗?对这个?

elasticsearch logstash kibana logstash-forwarder elastic-stack

3
推荐指数
2
解决办法
8900
查看次数

另一个类中的axon事件处理程序

我正在使用axon 2.3.1,我有一个聚合类

public class MyAggregate extends AbstractAnnotatedAggregateRoot<MBAggregate>   {


@AggregateIdentifier
private MyId Id;
private Circle circle;
EventDispatcher a=new EventDispatcher();

public MyAggregate() {
}

@CommandHandler
public MyAggregate(NewCommand command ) {
    apply(new SmallEvent(command.getId(), command.getCircle()));
}

@CommandHandler
public MyAggregate( StoreDestinationsCommand command ) {
    apply(new BigEvent(command.getId(), command.getCircle()));
}
//And some event handlers like

   @EventHandler                                                                                                                             
   public void onSmallEvent(SmallEvent event)    
   {
    //Some logic here
   }
   @EventHandler                                                                                                                             
   public void onBigEvent(BigEvent event)    
   {
    //Some logic here
   }
Run Code Online (Sandbox Code Playgroud)

现在我希望这些事件处理程序包含在其他类中,并在触发该事件时调用

public class EventContainer {


private static final long serialVersionUID = -6640657879730853388L; …
Run Code Online (Sandbox Code Playgroud)

axon eventhandler

2
推荐指数
1
解决办法
2739
查看次数

为什么Maven在target和groupId目录中为同一源创建两个jar

我有一个Maven项目,src并且pom具有以下内容groupIdartifactId

<groupId>com.useless.coders</groupId>
<artifactId>nonsense-program</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
Run Code Online (Sandbox Code Playgroud)

现在,当我们使用构建jar时mvn clean install,将创建一个目标文件夹,其名称和版本为nonsense-program-0.0.1。当我导航到.m2文件夹结构中的存储库时,com/useless/coders/我可以看到还使用额外的元数据信息创建了同一个jar maven-metadata-local.xml。我知道Maven存储库的用途,并且在target目录中,我们将构建的所有输出.class与jar和/或libs 生成的文件一起存放。

但是我很想知道为什么我们在target目录中维护两个相同源的jar副本,而在groupId路径目录中维护另一个。我们不会节省一些空间。

java jar target maven

2
推荐指数
1
解决办法
545
查看次数

字节数组[]到字节是否可以在java中?

我知道在java中我们不能直接处理bit,我想知道如何将byte array []转换为byte.这样

String bytestr="00000011";
byte[] noofbytes=bytestr.getBytes();
byte convbyte=(noofbytes[]) to byte
Run Code Online (Sandbox Code Playgroud)

可能吗 ?有谁有想法吗 ?谢谢.

java byte bytearray

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