我正在使用Spring 3.1.0.RELEASE.我的命令对象中有这个字段...
public Set<EventFeed> getUserEventFeeds() {
return this.userEventFeeds;
}
Run Code Online (Sandbox Code Playgroud)
在我的Spring JSP页面上,我想显示所有可能的事件源的复选框列表,然后检查复选框,如果用户在其集合中有一个.我希望在每个复选框周围都有一些特殊的HTML格式,所以我正在尝试......
<form:form method="Post" action="eventfeeds.jsp" commandName="user">
...
<c:forEach var="eventFeed" items="${eventFeeds}">
<tr>
<td><form:checkbox path="userEventFeeds" value="${eventFeed}"/></td>
<td>${eventFeed.title}</td>
</tr>
</c:forEach>
...
Run Code Online (Sandbox Code Playgroud)
但是,如果一个项目在集合中,则默认情况下不会检查这些项目.我该怎么做呢?这是我在控制器类中使用的活页夹...
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(EventFeed.class, new EventFeedEditor());
}
private class EventFeedEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(eventFeedsDao.findById(Integer.valueOf(text)));
}
@Override
public String getAsText() {
return ((EventFeed) getValue()).getId().toString();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring 3.1.1.RELEASE和Hibernate 4.1.0.Final.我得到了"无法初始化代理 - 无会话"异常,尽管事实上我正在将相关方法调用包装在@Transactional注释中.这是我的方法......
@Service("teacherImportService")
public class TeacherImportServiceImpl extends AbstractmyprojectService
{
…
@Transactional
@Override
public void saveUserObject(final JsonObject jsonData)
{
…
final myprojectOrganization myprojectOrg = myprojectOrgDao.findBymyprojectOrgId(myprojectSchoolId);
final Organization school = myprojectOrg != null ? myprojectOrg.getOrg() : null;
…
final Address address = new Address();
address.setState(school.getState()); // error occurs here
Run Code Online (Sandbox Code Playgroud)
我还需要做些什么来保证交易发生?我在我的应用程序上下文中包含了"<tx:annotation-driven />",我在下面包含了它
<context:component-scan base-package="org.mainco.subco" />
...
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${test.mysql.dataSource.driverClassName}" />
<property name="url" value="${test.mysql.dataSource.url}" />
<property name="username" value="${test.mysql.db.user}" />
<property name="password" value="${test.mysql.db.password}" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property …Run Code Online (Sandbox Code Playgroud) 我使用Spring 3.2.6.RELEASE,JUnit 4.11和DWR 3.0.0-rc2.我的问题是,在运行Spring-JUnit集成测试时,如何模拟正在运行的东西org.springframework.context.support.GenericApplicationContext?
我试过这个:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml", "classpath:dwr-context.xml" })
@WebAppConfiguration
public class MyServiceIT
{}
Run Code Online (Sandbox Code Playgroud)
我的"dwr-context.xml"文件设置为
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
<dwr:configuration>
<dwr:convert class="java.lang.StackTraceElement" type="bean"/>
</dwr:configuration>
<dwr:annotation-config id="annotationConfig" />
<dwr:annotation-scan base-package="org.mainco.subco" scanDataTransferObject="true" scanRemoteProxy="true" />
<dwr:url-mapping />
<dwr:controller id="dwrController" debug="false" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
<property name="urlMap">
<map>
<entry key="/dwr/**" value-ref="dwrController" />
</map>
</property>
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)
但是,我的所有JUnit测试最终都会因以下异常而死:
("java.lang.IllegalStateException:WebApplicationObjectSupport实例[org.directwebremoting.spring.DwrController@11297ba3]不在WebApplicationContext中运行,而是在:org.springframework.context.support.GenericApplicationContext@4e513d61")中运行.
如果我能弄明白如何欺骗系统运行,GenericApplicationContext我就会解决这个问题. …
我使用Wildfly 10.0.0.CR2和Java 8.我让Wildfly在端口8080上侦听http连接,并且过去使用此命令关闭服务器...
./jboss-cli.sh --connect command=:shutdown
Run Code Online (Sandbox Code Playgroud)
HOwever,偶尔,我无法访问此工具,即使服务器仍在运行.请注意我的Mac下面的交互...
Daves-MacBook-Pro-2:bin davea$ ./jboss-cli.sh --connect command=:shutdown
Failed to connect to the controller: The controller is not available at localhost:9990: java.net.ConnectException: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out: WFLYPRT0023: Could not connect to http-remoting://localhost:9990. The connection timed out
Daves-MacBook-Pro-2:bin davea$ telnet localhost 8080
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Run Code Online (Sandbox Code Playgroud)
我的问题是,什么是关闭JBoss服务器的万无一失的方法?注意我更喜欢不依赖于CLI工具的方法.
我正在使用Spring 3.2.11.RELEASE和JUnit 4.11.使用Spring mockMvc框架,如何检查返回JSON数据的方法是否包含特定的JSON元素?我有
mockMvc.perform(get("/api/users/" + id))
.andExpect(status().isOk())
.andExpect(content().string("{\"id\":\"" + id + "\"}"));
Run Code Online (Sandbox Code Playgroud)
但这会检查与返回的字符串的完全匹配,我宁愿检查JSON字符串是否包含我的本地字段"id"包含的值.
我正在使用Rails 5来使用Rails缓存来存储Nokogiri对象.
我在config/initializers/cache.rb中创建了这个:
$cache = ActiveSupport::Cache::MemoryStore.new
Run Code Online (Sandbox Code Playgroud)
我想存储以下文件:
$cache.fetch(url) {
result = get_content(url, headers, follow_redirects)
}
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
Error during processing: (TypeError) no _dump_data is defined for class Nokogiri::HTML::Document
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:671:in `dump'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:671:in `dup_value!'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache/memory_store.rb:128:in `write_entry'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:398:in `block in write'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:562:in `block in instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/notifications.rb:166:in `instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:562:in `instrument'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:396:in `write'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:596:in `save_block_result_to_cache'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/activesupport-5.0.2/lib/active_support/cache.rb:300:in `fetch'
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:116:in `get_cached_content'
/Users/davea/Documents/workspace/myproject/app/helpers/webpage_helper.rb:73:in `get_url'
/Users/davea/Documents/workspace/myproject/app/services/abstract_my_object_finder_service.rb:29:in `process_data'
/Users/davea/Documents/workspace/myproject/app/services/run_crawlers_service.rb:26:in `block (2 levels) in run_all_crawlers'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/Users/davea/.rvm/gems/ruby-2.4.0/gems/concurrent-ruby-1.0.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in …Run Code Online (Sandbox Code Playgroud) 我正在使用Python 3.7和Django.我有以下型号,带有另一个型号的外键......
class ArticleStat(models.Model):
objects = ArticleStatManager()
article = models.ForeignKey(Article, on_delete=models.CASCADE, related_name='articlestats')
...
def save(self, *args, **kwargs):
if self.article.exists():
try:
article_stat = ArticleStat.objects.get(article=self.article, elapsed_time_in_seconds=self.elapsed_time_in_seconds)
self.id = article_stat.id
super().save(*args, **kwargs, update_fields=["hits"])
except ObjectDoesNotExist:
super().save(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
如果相关的外键存在,我只想保存它,否则,我注意到错误结果.做这样的事情的标准Django/Python方法是什么?我以为我读过我可以使用".exists()"(检查一个对象是否存在),但我得到一个错误
AttributeError: 'Article' object has no attribute 'exists'
Run Code Online (Sandbox Code Playgroud)
编辑:这是我必须检查的单元测试...
id = 1
article = Article.objects.get(pk=id)
self.assertTrue(article, "A pre-condition of this test is that an article exist with id=" + str(id))
articlestat = ArticleStat(article=article, elapsed_time_in_seconds=250, hits=25)
# Delete the article
article.delete()
# Attempt to …Run Code Online (Sandbox Code Playgroud) 我正在使用Java 8,JUnit 4.12,Spring 4和Hibernate 5.2.12.Final。我想测试一个Hibernate方法,在其中更新一些行。方法看起来像这样
final CriteriaBuilder qb = m_entityManager.getCriteriaBuilder();
final CriteriaUpdate<FailedEvent> q = qb.createCriteriaUpdate(FailedEvent.class);
final Root<FailedEvent> root = q.from(FailedEvent.class);
q.where(qb.and( qb.equal(root.get(FailedEvent_.objectId), objectId) ));
q.set(root.get(FailedEvent_.flaggedForDelete), true);
affectedRows = m_entityManager.createQuery(q).executeUpdate();
return affectedRows > 0;
Run Code Online (Sandbox Code Playgroud)
我有以下JUnit测试来验证这一点
public class FailedEventDaoTest extends AbstractTransactionalJUnit4SpringContextTests
...
@Test
public final void testFlagForDeleteByObjectId()
{
final String eventId = "testId";
final FailedEvent event = failedEventDao.findByEventId(eventId);
Assert.assertFalse("A pre-condition fo this test is that an failed_event record with id \"" + eventId + "\" have a non-empty object id.", StringUtils.isEmpty(event.getObjectId()));
Assert.assertTrue(failedEventDao.flagForDeleteByObjectId(event.getObjectId())); …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 CentOS 7 上构建支持 SSL 的 Python 3.9.1。
[myuser@server Python-3.9.1]$ which openssl
/usr/local/bin/openssl
[myuser@server Python-3.9.1]$ openssl version
OpenSSL 1.1.1g 21 Apr 2020
Run Code Online (Sandbox Code Playgroud)
运行这个命令
sudo ./configure CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib" --with-ssl
Run Code Online (Sandbox Code Playgroud)
接下来的“make”适用于 Python 3.7,但是当我在 3.9 上运行上面的代码然后运行 make 时,我得到了这个输出
...
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_lzma _tkinter _uuid
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by …Run Code Online (Sandbox Code Playgroud) 我正在使用Spring 3.1.2.RELEASE.如果我的日期字段格式不正确,我想在我的JSP上显示错误消息.我以为我会遵循所有正确的步骤.我在控制器中绑定了一个转换器......
@InitBinder
public void initBinder(final WebDataBinder binder) {
final DateFormat dateFormat = new SimpleDateFormat(Contract.DATE_FORMAT);
dateFormat.setLenient(false);
// true passed to CustomDateEditor constructor means convert empty String to null
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
...
}
Run Code Online (Sandbox Code Playgroud)
我在messages.properties文件中包含了这些错误消息(包含在Spring应用程序上下文中)
typeMismatch.activationDate=The activation date format should be of the form MM/dd/yyyy
typeMismatch.sampleUserForm.activationDate=The activation date format should be of the form MM/dd/yyyy
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的模型:
public class SampleUserForm
{
private String userId;
private String firstName;
private String middleName;
private String lastName;
private String username;
private String url;
private String …Run Code Online (Sandbox Code Playgroud) spring ×6
java ×3
junit ×3
hibernate ×2
python ×2
transactions ×2
caching ×1
centos7 ×1
date ×1
django ×1
foreign-keys ×1
jboss ×1
json ×1
mockmvc ×1
model ×1
nokogiri ×1
openssl ×1
python-3.9 ×1
python-3.x ×1
return ×1
ruby ×1
shutdown ×1
spring-mvc ×1
unit-testing ×1
validation ×1
wildfly ×1