小编Moa*_*zam的帖子

在Spring Boot中定义logback shutdown hook

我在spring-boot(1.5.3.RELEASE)应用程序中使用AsyncAppender.

logback.xml

<appender name="FILE_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
    <queueSize>5000</queueSize>
    <discardingThreshold>0</discardingThreshold>
    <appender-ref ref="FILE" />
</appender>
Run Code Online (Sandbox Code Playgroud)

根据logback文档,

在应用程序关闭或重新部署时,必须停止AsyncAppender才能停止并回收工作线程并从队列中清除日志记录事件.

https://logback.qos.ch/manual/appenders.html

进一步说:

为了避免在这些条件下中断工作线程,可以在JVM运行时插入关闭挂钩,以便在启动JVM关闭后正确停止LoggerContext

我想知道如何在Spring Boot应用程序中停止AsyncAppender.在Spring Boot中的哪个位置,我应该定义shutdown hook吗?

logback spring-boot

7
推荐指数
3
解决办法
3319
查看次数

没有'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder'类型的限定bean

在Java项目中,我使用的是Sprig Boot 1.5.3.RELEASE.它连接两个数据库,即MongoDB和Microsoft SQLServer.当我用spring-boot运行它:运行目标时,它运行正常.但是,当我尝试使用目标运行它时,测试用例会报告以下错误,尽管这些测试用例未连接到SQL Server数据库:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    .....
    .....
Run Code Online (Sandbox Code Playgroud)

MediationTest.java(包含生成错误的测试用例的Java类)

@RunWith(SpringRunner.class)
@DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class)
@SpringBootTest(classes = { Application.class })
public class MediationTest {

    @Autowired
    private SwiftFormat swiftFormat;
    ......................
    ......................
Run Code Online (Sandbox Code Playgroud)

MsqlDbConfig.java

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "msqlEntityManagerFactory", transactionManagerRef = "msqlTransactionManager", basePackages …
Run Code Online (Sandbox Code Playgroud)

sql-server spring-data spring-boot

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

使用登录过滤器时缺少JSF页面样式

我使用以下过滤器来控制使用GlassFish作为应用程序服务器访问JSF 2.0中的所有页面.问题是,使用此代码虽然过滤器工作正常,如果用户尝试直接访问任何其他页面,但用户将重定向到log.xhtml但是login.xhtml看起来不太好(没有显示彩色图像,而页面形状发生变化),因为它应该是.但是,如果我删除sendRedirect语句并将其替换为chain.doFilter语句,那么页面显示方式应该看起来不错,但是过滤效果不明显.我该如何解决这个问题?

LoggingFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {   
    HttpServletRequest req = (HttpServletRequest) request;
    LoginBean auth = (LoginBean) req.getSession().getAttribute("loginBean");




    if ((auth != null && auth.isLoggedIn()) || req.getRequestURI().endsWith("/login.xhtml")) {
        // User is logged in, so just continue request.
        HttpServletResponse httpResponse = (HttpServletResponse)response;
        httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
        httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0.
        httpResponse.setDateHeader("Expires", 0); // Proxies.
        chain.doFilter(request, response);
    } else {
        // User is not logged in, so redirect to index.
        HttpServletResponse res …
Run Code Online (Sandbox Code Playgroud)

jsf

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

标签 统计

spring-boot ×2

jsf ×1

logback ×1

spring-data ×1

sql-server ×1