Spring框架可以使用基于XML的配置覆盖基于注释的配置吗?我需要更改已经通过注释定义的bean的依赖项,而我不是bean的作者.
那么,是否可以混合两种配置而不是仅使用其中一种?
我想要的只是通过Annotations保留所有配置并通过XML读取表.
可能吗?
非常感谢.
编辑:hbm.xml文件怎么样?我有这个:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="MyData" table="MyTable" >
</class>
</hibernate-mapping>
Run Code Online (Sandbox Code Playgroud)
并且不要编译dtd.
I am working on a Spring application on Tomcat7, JDK1.7, Maven and other components. Recently, I made a major change to the application, requiring switching over to Spring 3. After the change, I'm seeing the below exception on deploying to dev server. The application runs flawlessly on my local system though.
javax.servlet.ServletException: Servlet.init() for servlet amadeusAce threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
root cause
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/amadeusAce-servlet.xml]; …Run Code Online (Sandbox Code Playgroud) 在我读过的一本书中,XML配置的优先级高于注释配置.
但是没有任何例子.
你能举例说明一下吗?
我希望使用NHibernate创建多对多的关系.我不确定如何在XML文件中映射这些.我还没有创建类,但它们只是基本的POCO.
人
PERSONID
名
能力
胜任
标题
Person_x_Competency
personId
competencyId
我是否会在每个POCO中为另一个类创建一个List?然后使用NHibernate配置文件以某种方式映射它们?
nhibernate many-to-many nhibernate-mapping xml-configuration
我花了几个小时试图让Twitter集成与Spring Social一起使用XML配置方法.我可以在Web上(以及在stackoverflow上)找到的所有示例始终使用示例中@Config显示的方法
无论出于何种原因,获取twitter API实例的bean定义都会引发AOP异常:
Caused by: java.lang.IllegalStateException: Cannot create scoped proxy for bean 'scopedTarget.twitter': Target type could not be determined at the time of proxy creation.
Run Code Online (Sandbox Code Playgroud)
这是我的完整配置文件:
<?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:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/DefaultDB" />
<!-- initialize DB required to store …Run Code Online (Sandbox Code Playgroud) 我有以下spring xml配置头:
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
....
Run Code Online (Sandbox Code Playgroud)
当我在想法中打开文件时,我看到红色错误:1.xmlns:p="http://www.springframework.org/schema/p -
URI未注册

但它运作良好.
如何避免红色错误?
我的xml配置中有以下片段:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">${jdbc.dialect}</prop>
<prop key="hibernate.connection.charSet">UTF-8</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hbm2ddl.auto">validate</prop>
</props>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud) 当我第一次运行程序时,这个错误不存在,然后我尝试了一些实验来获得MVC架构的流程,但现在它向我展示了这个异常.
我想问题是,当我通过订阅按钮请求时,它将转到struts.xml它将寻找动作的位置.问题是在包标签中应该有什么
java.lang.NullPointerException
org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:501)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
/*This package*/
<package name="Struts2Ex2" extends="struts.default">
<action name="test"
class="MyPack.Verify"
method="execute">
<result name="success">/Test2/WelcomeHome.jsp</result>
</action>
</package>
</struts>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Hibernate将数据库记录显示到Struts 2中的JSP页面.我成功完成了检索部分.
但无论我做什么,我似乎都无法在JSP页面中显示数据.
我试过在互联网上找到各种解决方案.但是无法理解什么似乎是问题所在.我可以看到表列名,但其中没有数据.我在User POJO课程中拥有所有必需的getter和setter.
我附上了我的代码:
注册行动:
public class RegisterAction extends ActionSupport{
String name,pwd,email,address;
int phno;
public RegisterAction() {}
List<User> users = new ArrayList<User>();
UserDao udao = new UserDao();
//Getters and setters.
public String execute() throws Exception {
User u=new User();
u.setName(name);
u.setEmail(email);
u.setAddress(address);
u.setPhno(phno);
u.setPwd(pwd);
udao.addUser(u);
return "success";
}
public String listAllUsers(){
users = udao.getUsers();
System.out.println("In Action, "+users);
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)
UserDao:
public class UserDao{
List<User> allUsers = new ArrayList<User>();
public UserDao() {}
//Getter and setter.
public …Run Code Online (Sandbox Code Playgroud) ehcache 3.x 版本中需要将缓存保存到磁盘时如何指定磁盘路径。在 ehcache 2.x 版本中可以使用 指定<diskStore path="java.io.tmpdir/ehcache/" />,但在 3.x 版本中我没有找到任何等效的 xml 标记。
java ×5
spring ×5
annotations ×3
hibernate ×2
struts2 ×2
aop ×1
ehcache-3 ×1
jsp ×1
many-to-many ×1
maven ×1
nhibernate ×1
pom.xml ×1
spring-3 ×1
spring-aop ×1
spring-mvc ×1
tomcat7 ×1
validation ×1