- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这与此相关:
Suddenly my spring.xml won't instantiate my classes and Error Exception occurs
作为建议,我将 spring XML 更改为 applicationContext.xml。我没有使用 getbeans() 来实例化工厂中的 bean。相反,我使用上述 xml 进行对象注入(inject)。
但是我有一个问题。有错误:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recordexistuserprofile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'registeraction' while setting bean property 'registeraction'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registeraction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'insertUserProfile' while setting bean property 'insertUserProfile'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204)
at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'registeraction' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'insertUserProfile' while setting bean property 'insertUserProfile'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'insertUserProfile' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:269)
... 39 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'registeraction' of bean class [lotmovement.business.crud.InsertUserProfile]: Bean property 'registeraction' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:801)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:651)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:59)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1276)
这很奇怪,因为我通过 netbeans 自动添加 setter。应该没有错误。
这是我的 applicationContext.xml。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="userprofile" class="lotmovement.business.entity.UserProfile">
</bean>
<bean id="entitystart"
class="lotmovement.business.crud.EntityStart">
</bean>
<bean id="recordexistuserprofile"
class="lotmovement.business.crud.RecordExistUserProfile">
<property name="registeraction" ref="registeraction"/>
<property name="entitystart" ref="entitystart"/>
</bean>
<bean id="insertUserProfile" class="lotmovement.business.crud.InsertUserProfile">
<property name="registeraction" ref="registeraction"/>
<property name="entitystart" ref="entitystart"/>
<property name="userprofile" ref="userprofile"/>
</bean>
<bean id="registeraction" class="lotmovement.action.RegisterAction">
<property name="insertUserProfile" ref="insertUserProfile"/>
<property name="entitystart" ref="entitystart"/>
<property name="recordexistuserprofile" ref="recordexistuserprofile"/>
</bean>
</beans>
Web.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>register.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
我的类(class):
注册操作
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package lotmovement.action;
import com.opensymphony.xwork2.ActionSupport;
import lotmovement.business.crud.ApplicationContextProvider;
import lotmovement.business.crud.EntityStart;
import lotmovement.business.crud.InsertUserProfile;
import lotmovement.business.crud.RecordExistUserProfile;
import lotmovement.business.entity.UserProfile;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class RegisterAction extends ActionSupport {
private static String userId;
private static String password;
private static String firstName;
private static String lastName;
private static int securityLevel;
EntityStart es;
InsertUserProfile iup;
RecordExistUserProfile reup;
ApplicationContextProvider acp = new ApplicationContextProvider();
ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
@Override
public void validate() {
if (reup.checkrecordexist()) {
addActionError("record already exist.");
}
}
@Override
public String execute() {
iup.Insert();
return SUCCESS;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getSecurityLevel() {
return securityLevel;
}
public void setSecurityLevel(int securityLevel) {
this.securityLevel = securityLevel;
}
private String retypepassword;
public String getRetypepassword() {
return retypepassword;
}
public void setRetypepassword(String retypepassword) {
this.retypepassword = retypepassword;
}
// * Object setter.
public void setEs(EntityStart es) {
this.es = es;
}
public void setIup(InsertUserProfile iup) {
this.iup = iup;
}
public void setReup(RecordExistUserProfile reup) {
this.reup = reup;
}
}
应用程序上下文提供程序
package lotmovement.business.crud;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ApplicationContextProvider implements ApplicationContextAware{
private static ApplicationContext ctx = null;
public static ApplicationContext getApplicationContext() {
return ctx;
}
public void setApplicationContext(ApplicationContext ctx) throws BeansException {
this.ctx = ctx;
}
}
实体开始
package lotmovement.business.crud;
import lotmovement.business.CRUDxxxx.*;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import lotmovement.business.entity.UserProfile;
public class EntityStart {
EntityManagerFactory factory;
EntityManager em;
public void StartDbaseConnection()
{
factory = Persistence.createEntityManagerFactory("LotMovementPU");
em = factory.createEntityManager();
}
public void StartPopulateTransaction(Object entity){
EntityTransaction userTransaction = em.getTransaction();
userTransaction.begin();
em.persist(entity);
userTransaction.commit();
em.close();
}
public void CloseDbaseConnection(){
factory.close();
}
}
插入用户配置文件
package lotmovement.business.crud;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import lotmovement.business.entity.UserProfile;
import lotmovement.action.LoginAction;
import lotmovement.action.RegisterAction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class InsertUserProfile {
ApplicationContextProvider acp = new ApplicationContextProvider();
ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
UserProfile up;
RegisterAction ra;
EntityStart es;
public void Insert() {
up.setUserId(ra.getUserId());
up.setFirstName(ra.getFirstName());
up.setLastName(ra.getLastName());
up.setPassword(ra.getPassword());
up.setSecurityLevel(ra.getSecurityLevel());
es.StartPopulateTransaction(up);
es.CloseDbaseConnection();
}
public void Update() {
}
public void Delete() {
}
public void setUp(UserProfile up) {
this.up = up;
}
public void setRa(RegisterAction ra) {
this.ra = ra;
}
public void setEs(EntityStart es) {
this.es = es;
}
}
检查记录是否存在
package lotmovement.business.crud;
import lotmovement.action.RegisterAction;
import lotmovement.business.entity.UserProfile;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class RecordExistUserProfile {
RegisterAction ra;
EntityStart es;
ApplicationContextProvider acp = new ApplicationContextProvider();
ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
public boolean checkrecordexist() {
UserProfile up = es.em.find(UserProfile.class, ra.getUserId());
if (ra.getUserId().equals(up.getUserId())) {
return true;
} else {
return false;
}
}
public void setRa(RegisterAction ra) {
this.ra = ra;
}
public void setEs(EntityStart es) {
this.es = es;
}
}
我在 netbeans 中所做的就是将 spring 库添加到我的类路径中。它们是 struts 2.3.4、springframework 2.5.6 SEC03 和 SpringFramework 3.1.1。我也查过网络,但找不到类似的东西..
非常感谢。
最佳答案
首先,我建议您探索 Struts 2 Spring 集成,而不是尝试自己将 Spring 集成到 Struts 2 中。该集成由 Strut 2 Spring 插件提供。你应该检查一下;它允许您轻松地将 bean 注入(inject)到 struts 2 操作中,更不用说框架创建的所有其他对象了。 Here's a link .
但是,即使根据您的代码片段中的内容,我也可以提供一些 Spring 基础知识的清晰说明。 setter 定义的 bean 属性必须与 bean 属性名称匹配。如果没有这个,属性(property)注入(inject)就无法进行。但是,听起来您更改了字段本身的名称以匹配;这将是现场注入(inject)。完全不同的机制。我建议你确实需要理解属性注入(inject)、字段注入(inject)和构造函数注入(inject)的概念,以及 Autowiring 的概念。抱歉,如果我误认为您没有调用此电话;看来你不这么认为。
但是,我建议你有一个更大的问题。你的 bean 中有一个依赖循环。考虑这两个:
<bean id="insertUserProfile" class="lotmovement.business.crud.InsertUserProfile">
<property name="registeraction" ref="registeraction"/>
<property name="entitystart" ref="entitystart"/>
<property name="userprofile" ref="userprofile"/>
</bean>
<bean id="registeraction" class="lotmovement.action.RegisterAction">
<property name="insertUserProfile" ref="insertUserProfile"/>
<property name="entitystart" ref="entitystart"/>
<property name="recordexistuserprofile" ref="recordexistuserprofile"/>
</bean>
我不确定 spring 是否允许这样做,但如果允许,则必须对注入(inject)如何进行做出一些武断的决定,因为我认为,它根本不可能以正常方式满足循环。
关于java - Spring 注入(inject)错误, Spring 对象注入(inject)的对象 setter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13562720/
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!