上下文:
我从基于XML的Spring配置切换到了基于Java的配置.我的应用程序有一个基于JSP的Web层,Spring MVC,Spring Security和Hibernate作为持久性提供程序.
我设法在不同的配置类中分离整个XML配置:
WebConfig- 用于Spring MVC配置;
PersistenceConfig - 正如名称所述 - 用于JPA配置;
ServiceConfig - 仅适用于@Service和@Component注释类;
SecurityConfig - 用于Spring安全配置.
对于应用程序初始化,我有SecurityInitializer和WebAppInitializer类.
这是一些代码:
WebConfig
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.demo.app.web"})
public class WebConfig extends WebMvcConfigurerAdapter { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
PersistenceConfig
@Configuration
@ComponentScan(basePackages = {"com.demo.app.dao"})
@EnableTransactionManagement(mode = AdviceMode.PROXY, proxyTargetClass = true)
public class PersistenceConfig { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
ServiceConfig
@Configuration
@ComponentScan(basePackages = {"com.demo.app.service", "com.demo.app.component"})
public class ServiceConfig { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
SecurityConfig
@Configuration …Run Code Online (Sandbox Code Playgroud) 有人能告诉我有没有一种方法可以在@Async不阻塞/等待结果的情况下使用 Spring 框架的注释?这是一些代码来澄清我的问题:
@Service
public class AsyncServiceA {
@Autowired
private AsyncServiceB asyncServiceB;
@Async
public CompletableFuture<String> a() {
ThreadUtil.silentSleep(1000);
return asyncServiceB.b();
}
}
@Service
public class AsyncServiceB {
@Async
public CompletableFuture<String> b() {
ThreadUtil.silentSleep(1000);
return CompletableFuture.completedFuture("Yeah, I come from another thread.");
}
}
Run Code Online (Sandbox Code Playgroud)
和配置:
@SpringBootApplication
@EnableAsync
public class Application implements AsyncConfigurer {
private static final Log LOG = LogFactory.getLog(Application.class);
private static final int THREAD_POOL_SIZE = 1;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext …Run Code Online (Sandbox Code Playgroud) 我data table在选择日期时遇到问题<rich:calendar>.我<a4j:ajax>用于渲染但没有效果.这是代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:composite="http://java.sun.com/jsf/composite">
<rich:panel header="#{lang.reportPanelHeader}" id="panel" rendered="#{navigation.reportRendered}" width="700px" style="margin-left:250px">
<a4j:status onstart="#{rich:component('statPane')}.show()" onstop="#{rich:component('statPane')}.hide()" />
<h:form id="data_table_form">
<rich:dataTable value="#{validateReportAction.reportList}" var="report" iterationStatusVar="it" id="data_table" rows="5">
<rich:column>
<f:facet name="header">#</f:facet>
#{it.index + 1}
</rich:column>
<rich:column>
....
</rich:column>
<f:facet name="footer">
<rich:dataScroller page="#{validateReportAction.page}" />
</f:facet>
</rich:dataTable>
</h:form>
<rich:popupPanel id="statPane" autosized="true" style="border: none; background-color: #e6e6e6;">
....
</rich:popupPanel>
<div id="bottom">
<h:form id="calendarForm">
<div id="left">
<div class="input" id="test_cal">
<rich:calendar
dataModel="#{calendarModel}" …Run Code Online (Sandbox Code Playgroud) 在项目中,我使用Seam 3,我注射有问题EntityManager与@Inject注解.我很确定有某种配置可以确保EnityManager知道PersistenceUnit要使用哪种配置.例如,EJB你可以输入:
@PersistenceContext(unitName="MY_PERSISTENCE_UNIT_NAME")
private EntityManager eManager;
Run Code Online (Sandbox Code Playgroud)
在persistence.xml文件中配置了哪个持久性单元.这是我的伪配置:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MY_PERSISTENCE_UNIT_NAME" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/TimeReportDS</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<class>....</class>
<class>....</class>
<class>....</class>
<properties>
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/modelEntityManagerFactory" />
<!-- PostgreSQL Configuration File -->
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.connection.url" value="jdbc:postgresql://192.168.2.125:5432/t_report" />
<property name="hibernate.connection.username" value="username" />
<!-- Specifying DB Driver, providing hibernate cfg lookup
and providing transaction manager configuration -->
<property …Run Code Online (Sandbox Code Playgroud) 我使用Eclipse Juno,我做了2个项目:
EAR Project -> Export -> Java EE -> EAR fileWEB -> WAR file在export导航菜单中选择.部署WAR后,一切正常. 现在我做整个"导出"事情的原因是因为Run as -> Run on server它不构建和部署我的项目.我认为这是它的主要目标.我错了吗?有没有办法让这个命令像我预期的那样工作?我认为它与Tomcat和Web项目一起工作......
我知道这可以通过构建脚本轻松完成,但这不是我的观点!
在此先感谢您的帮助和建议.
我在使用 xsl 将 xml 转换为 xml 时遇到问题。我找到了问题出在哪里,但仍然不知道如何解决。
<?xml version="1.0" encoding="UTF-8"?>
<tells uri="" xmlns="http://dl.kr.org/dig/2003/02/lang">
<impliesc>
<catom name="name1"/>
<catom name="name2"/>
</impliesc>
<impliesc>
<catom name="name3"/>
<catom name="name4"/>
</impliesc>
</tells>
Run Code Online (Sandbox Code Playgroud)
我认为问题来自这一行
<tells uri="" xmlns="http://dl.kr.org/dig/2003/02/lang">
Run Code Online (Sandbox Code Playgroud)
如果我删除“uri =”“xmlns =”http://dl.kr.org/dig/2003/02/lang“”并仅保留
"<tells>"
Run Code Online (Sandbox Code Playgroud)
一切都很完美。但有没有一种方法可以在不删除它的情况下对其进行改造呢?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="tells">
<xsl:for-each select="./tells/impliesc">
<xsl:element name="impliesc">
<xsl:for-each select="./tells/impliesc/catom">
<xsl:element name="catom">
<xsl:attribute name="name">
<xsl:value-of select="./tells/impliesc/individual/@name"/>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud) 我使用rich:具有特定模式的日历datePattern="dd/MM/yyyy".当我试图从日历中获取字符串值并使用解析它时SimpleDateFormat ("dd/MM/yyyy")遇到了一些问题,我看到变量中的日期格式与我的预期不符:Tue Nov 22 00:00:00 EET 2011
这是一些代码:
富人:日历
<rich:calendar value="#{validateReportAction.selectedDate}"
required="true"
requiredMessage="You must select a date"
mode="ajax"
id="date"
datePattern="dd/MM/yyyy"/>
Run Code Online (Sandbox Code Playgroud)
在豆
DateFormat formatter;
Date date;
formatter = new SimpleDateFormat("dd/MM/yyyy");
date = (Date) formatter.parse(getSelectedDate());
Run Code Online (Sandbox Code Playgroud)
哪里有getSelectedDate()退货,Tue Nov 22 00:00:00 EET 2011但我只想要日/月/年.我怎样才能做到这一点?
技术栈
问题
我需要能够处理应用程序中包含文档的ZIP文件,然后以递归方式解压缩它们。我的意思是递归-如果ZIP包含其他ZIP文件,它们也应该解压缩。然后,应处理所有档案中的所有文档。
点1应该并行执行,以加快处理速度。
实作
compute()方法检查,如果该组的ZIP内容是足够小(文档集合大小为1)直接计算,还是应与分隔继续。如果应该直接计算,则检查当前内容/文件是否实际上是要处理的文件,还是另一个(嵌套的)ZIP。这是有趣的部分-当我创建我将ZipService中的ZipPartitioner传递this给其构造函数,因此我对ZipService进行了引用。然后,如果直接在计算逻辑中发现内容实际上又是一个ZIP,那么我从ZipService的引用中调用process(zip)方法,以便该过程可以递归地重新开始。结果
题
让我知道我的解释中有哪些不清楚的地方(我敢打赌会有些东西)。
我有一个JSF 2.0页面,用户可以在其中登录,他可以选择注销(令人惊讶)。我的JBoss服务器配置最多允许7个线程(连接)。我与一位用户测试了几次页面登录,然后尝试进行7次尝试Transaction not active,这也许意味着注销后连接不会重新回到池中并保持打开状态。
问:注销和返回线程池中的线程的方法是什么?这个问题困扰了我很长时间。请帮忙。
这是我的JBoss中standalone.xml用于限制连接的数据源的配置:
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jndi-name="java:jboss/MyJndiDS" pool-name="MyPoolDS" enabled="true" jta="true" use-java-context="false" use-ccm="true">
<connection-url>
jdbc:postgresql://192.168.2.125:5432/t_report
</connection-url>
<driver>
org.postgresql
</driver>
<transaction-isolation>
TRANSACTION_READ_COMMITTED
</transaction-isolation>
<pool>
<min-pool-size>
3
</min-pool-size>
<max-pool-size>
7
</max-pool-size>
<prefill>
true
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
FailingConnectionOnly
</flush-strategy>
</pool>
<security>
<user-name>
my_user
</user-name>
<password>
my_pass
</password>
</security>
<statement>
<prepared-statement-cache-size>
32
</prepared-statement-cache-size>
</statement>
</datasource>
...
...
</datasources>
</subsystem>
Run Code Online (Sandbox Code Playgroud)
和在注销方法@SessionScoped类
import javax.faces.context.ExternalContext;
...
...
@Inject ExternalContext ec;
public void validateUserLogOut() {
HttpServletRequest request …Run Code Online (Sandbox Code Playgroud) java ×6
spring ×3
java-ee ×2
jsf-2 ×2
richfaces ×2
ajax ×1
asynchronous ×1
cdi ×1
deployment ×1
eclipse ×1
jboss ×1
jboss6.x ×1
jpa ×1
jsf ×1
locking ×1
nonblocking ×1
persistence ×1
recursion ×1
seam3 ×1
servlet-3.0 ×1
threadpool ×1
xml ×1
xslt ×1