Why are my @components not detected by spring? -
this 1 tricky - me @ least.component scan not seem work
here web.xml
<!doctype web-app public "-//sun microsystems, inc.//dtd web application 2.3//en" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>geomajas gwt face example application</display-name> <context-param> <param-name>contextconfiglocation</param-name> <param-value> classpath:org/geomajas/spring/geomajascontext.xml classpath:org/geomajas/plugin/rasterizing/defaultrasterizedpipelines.xml web-inf/applicationcontext.xml <!-- web-inf/applicationcontext2.xml --> <!-- web-inf/layer*.xml --> <!-- web-inf/map*.xml --> web-inf/layerosm.xml web-inf/maposm.xml <!-- web-inf/applicationcontext2.xml --> </param-value> </context-param> <filter> <filter-name>cachefilter</filter-name> <filter-class>org.geomajas.servlet.cachefilter</filter-class> </filter> <filter-mapping> <filter-name>cachefilter</filter-name> <url-pattern>*</url-pattern> </filter-mapping> <listener> <listener-class>org.geomajas.servlet.preparescanningcontextlistener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener> <servlet> <servlet-name>geomajasserviceservlet</servlet-name> <servlet-class>org.geomajas.gwt.server.geomajasserviceimpl</servlet-class> </servlet> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>classpath*:meta-inf/geomajaswebcontext.xml</param-value> <description>spring web-mvc specific (additional) context files.</description> </init-param> <load-on-startup>3</load-on-startup> </servlet> <!-- springgwt remote service servlet --> <servlet> <servlet-name>springgwtremoteserviceservlet</servlet-name> <servlet-class>org.spring4gwt.server.springgwtremoteserviceservlet</servlet-class> <init-param> <param-name>contexconfiglocation</param-name> <param-value>web-inf/applicationcontext2.xml</param-value> <description>j</description> </init-param> </servlet> <servlet-mapping> <servlet-name>geomajasserviceservlet</servlet-name> <url-pattern>/showcase/geomajasservice</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/d/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>springgwtremoteserviceservlet</servlet-name> <url-pattern>/showcase/springgwtservices/test</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
and service :
@service("test") public class projserviceimpl extends remoteserviceservlet implements projservice { private static final log log = logfactory.getlog(projserviceimpl.class); @autowired poicategdao poicategdao; public string greetserver(string input) throws illegalargumentexception { // verify input valid. if (!fieldverifier.isvalidname(input)) { // if input not valid, throw illegalargumentexception // client. throw new illegalargumentexception( "name must @ least 4 characters long"); } //requestcontextutils.getwebapplicationcontext(request); // string serverinfo = getservletcontext().getserverinfo(); // string useragent = getthreadlocalrequest().getheader("user-agent"); return "hello, " + input + "!<br><br>i running .<br><br>it looks using:<br>"; } @override //@transactional(propagation = propagation.required, rollbackfor = exception.class) public void testdao(integer id) throws illegalargumentexception { // todo auto-generated method stub poicateg x=poicategdao.findbyid(id); poicateg z=poicategdao.findbyid(id); } }
and applicaationcontext2.xml
<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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemalocation=" http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 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.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <context:annotation-config /> <tx:annotation-driven transaction-manager="transactionmanager" /> <context:component-scan base-package="ne.projl.*" /> <!-- <context:component-scan base-package="fully qualified" /> --> <bean class="org.springframework.orm.jpa.localentitymanagerfactorybean" id="entitymanagerfactory"> <property name="persistenceunitname" value="mypunit" /> </bean> <bean class="org.springframework.orm.jpa.jpatransactionmanager" id="transactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory" /> </bean> </beans>
please note if put context:component-scan in applicationcontext.xml ( not applicatincontext2.xml service bean detected. ). if there's other info should provide tell.
if remember correctly, base package in component scan requires package name. underlying sub-package included.
therefore correct setting should
<context:component-scan base-package="ne.projl" />
Comments
Post a Comment