Error enabling SpringBeanAutowiringSupport within a JAX-WS web service - java

I am trying to enable Spring autowiring support in my webservice, following the lines of
public class MyService extends SpringBeanAutowiringSupport implements SomeInterface {
private Dao dao;
#Autowired
public void setDao(Dao dao) {
this.dao = dao;
}
With the MyService class annotated with
#WebService(endpointInterface = "SomeInterfacePath")
However, when I try and run this, I get a
java.lang.NoSuchMethodError: org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext()Lorg/springframework/web/context/WebApplicationContext;
at org.springframework.web.context.support.SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(SpringBeanAutowiringSupport.java:81)
at org.springframework.web.context.support.SpringBeanAutowiringSupport.<init>(SpringBeanAutowiringSupport.java:68)
error, which I haven't been able to find a resolution to. I'm using Spring 3.0 jars and apache-cxf. Spring autowiring works elsewhere in my project but doesn't seem to play nicely here. Any ideas as to what is going on? I have a a jaxws endpoint defined in my appConfig as
<jaxws:endpoint
id="myendpoint"
implementor="MyService"
address="/helloworld
/>

Until recently, Apache CXF pulled Spring 2.5.5 as a maven dependency.
However, CXF Version 2.3 and newer use Spring 3.
Apache CXF parent pom 2.2.1:
<spring.version>2.5.5</spring.version>
Apache CXF parent pom 2.3:
<spring.version>3.0.4.RELEASE</spring.version>
Both include a <dependencymanagement> section that ties Spring to the specified version.

Related

Spring Boot Application giving 404 after upgrading to springboot 2.6.6

I have changed the spring boot version of my web application from 2.1.2 to 2.6.6 . Here is the POM---
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.6</version>
<relativePath>/</relativePath> <!-- lookup parent from repository -->
</parent>
A1fter version upgrade I faced some circular dependency issues which I resolved using constructor injection with #Lazy annotation. Below is example---
#Autowired
public ServiceImpl(#Lazy ABCService abcService,
#Lazy XYZService xyzService,
#Lazy PQRMapper pqrMapper,
#Lazy PQRService pqrRepositoryService) {
super();
this.abcService = abcService;
this.xyzService = xyzService;
this.pqrMapper = pqrMapper;
this.pqrRepositoryService = pqrRepositoryService;
}
But if I am trying to hiit any API it is giving me 404.
Can anyone suggest what I can do to resolve this.
I found the issue after going through all the release documents, I figured out that spring-boot disables the default-dispatcher-servlet. so we need to enable it with property-
server.servlet.register-default-servlet=true
This solution worked for me.
in log there is info exposing one endpoint beneath base path '/internal'
maybe those controllers you try to use are not created maybe package is not scaned

#ComponentScan seens not to be working after migrate from Spring Boot 2.0 to 2.5

I have an application that was working in Spring Boot 1.5, than worked in 2.0.
Now I'm migrating to 2.5.7
This application uses a external lib. This lib also written using Spring Boot 2.5.7 and it users OpenFeign.
But now, when running, the main application seens not to be scanning the lib.
The error is:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field usersRestClient in my.library.package.infrastructure.acl.facade.user.UserFacade required a bean of type 'my.library.package.infrastructure.acl.restclient.user.UsersRestClient' that could not be found.
The injection point has the following annotations:
- #javax.inject.Inject()
Action:
Consider defining a bean of type 'my.library.package.acl.restclient.user.UsersRestClient' in your configuration.
I already tried to use ComponentScan at diferent places. I tried to Create a Configuration Class with ComponentScan at the lib and point in the main application using #Import.
Nothing worked.
I've edited the code leaving just whats matters.
In the lib:
The Service UserFacade uses the Component UsersRestClient
#Service
// I've already tried to put #ComponentScan here, didn't work.
public class UserFacade {
#Autowired
private UsersRestClient usersRestClient;
...
}
This is the component:
#RequestMapping("/users")
#Component("usersRestClient")
public interface UsersRestClient {
...
}
In the main App:
The main class
#SpringBootApplication
#ComponentScan(basePackages = {"my.library.package"})
#EnableAutoConfiguration
#EnableFeignClients({"my.library.package"})
public class ResourceAllocationServiceApplication {
...
}
Than, where I use the UseFacade Service:
#Component
public class RetrieveUserByIdUseCase {
#Autowired
private UserFacade userFacade;
...
}
Can anyone help? I found a similar issue here, but no answers worked.
#ComponentScan on external library not working

EJB Injection Between EARs on the Same Server

I'm running into an issue trying to migrate an application from Jboss AS6 to Wildfly. The application consists of a 'Product' ear, a 'Person' ear, and a 'Common' jar containing shared interfaces and utilities. All are being deployed as modules on a Wildfly application server. I need to be able to inject a service bean defined in Person into Product. The LoginService bean is located in Person and looks like this:
#Stateless
#Remote(LoginService.class)
public class LoginServiceBean implements LoginService {
#Resource
protected SessionContext context;
}
When I build and deploy the Person ear, I get the following log for my jndi bindings:
java:global/Person/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService
java:app/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService
java:module/LoginServiceBean!com.tura.common.service.login.LoginService
java:jboss/exported/Person/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService
ejb:Person/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService
java:global/Person/Person-ejb/LoginServiceBean
java:app/Person-ejb/LoginServiceBean
java:module/LoginServiceBean
In the Product project I then have a stateless EJB bean
#Stateless(name = "ClientServiceProvider")
public class ClientServiceProviderBean implements ClientServiceProvider{
#EJB(name = "ejb:Person/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService")
protected LoginService loginService;
}
When I try to deploy, it then fails with the error:
No EJB found with interface of type
'com.tura.common.service.login.LoginService' for binding
ejb:Person/Person-ejb/LoginServiceBean!com.tura.common.service.login.LoginService"
I've tried every binding configuration I can think of; nothing seems to work. All the documentation I can find seems to want to use a manual jndi lookup rather than the annotation. What am I doing wrong here? Is there really no way to inject services between EARs?

Access Spring beans from Alfresco integration test context

Now that Alfresco integration tests of custom modules are run using Docker, I wonder how to make additional Spring beans available in this context and how to access existing Spring beans in test classes.
Until Alfresco 5.x, I used to annotate the test class with
#ContextConfiguration("classpath:alfresco/application-context.xml")
This made the Spring context available. To make Spring beans from this context available in the test class, I annotated members like this:
#Autowired
#Qualifier("authenticationComponent")
private AuthenticationComponent authenticationComponent;
In addition I was able to define additional Spring beans in src/test/resources/alfresco/extension/test-context.xml.
Is this the approach to use when writing integration tests for 6.x and Docker?
At least the annotation org.springframework.test.context.ContextConfiguration is no longer included in a module build using the Maven 4.0.0 SDK archetype.
This blog post talks about the above mentioned annotations. But the dependencies pulled in by the pom.xml created from the SDK 4 archetype don't include these annotations.
A different approach seems to be to only use
#RunWith(value = AlfrescoTestRunner.class)
on the integration test class. But how do I get the Spring beans like nodeService injected into it? And how do I declare and make available additional Spring beans which are part of my custom module and required by the integration test to succeed?
You can get the Spring context via AlfrescoTestRunner as follows:
#Before
public void setUp() {
this.nodeService = (NodeService) super.getApplicationContext().getBean("nodeService");
}
I do the same with custom beans:
super.getApplicationContext().getBean(MyType.class);
Since the integration tests run in the repository, all of the Spring context is automatically available.
Note that your test class needs to extend AbstractAlfrescoIT for this to work.
An example class may look like this:
package nl.open.mystuff;
import org.alfresco.rad.test.AbstractAlfrescoIT;
import org.alfresco.rad.test.AlfrescoTestRunner;
import org.alfresco.service.cmr.repository.NodeService;
#RunWith(value = AlfrescoTestRunner.class)
public class MyCustomIT extends AbstractAlfrescoIT {
private NodeService nodeService;
private MyType myType;
#Before
public void setUp() {
this.nodeService = (NodeService) super.getApplicationContext().getBean("NodeService");
this.myType = super.getApplicationContext().getBean(MyType.class);
}
}
In Alfresco SDK 3, you can even add your own Spring XML files under src/test/resources/alfresco/extension/*-context.xml. I imagine this still works, but I haven't tried it with SDK 4 myself.

Two differents projects in eclipse: (JPA & EJB) in a EAR Project (problems with CDI)

Hy guys, first: My english is not good, but.. come on:
I have two projects in eclipse:
JPA (with models & dao's)
EJB (with my web services)
and an EAR Project (JPA + EJB). My setup: JBoss 7.1 AS
My problem:
#Stateless
#WebService --> THIS IS IN EBJ PROJECT
public class PessoaFisicaWS implements Service {
#EJB
private PessoaFisicaDAO dao;
}
this is my DAO Impl
#Stateless ->> THIS IS IN MY JPA PROJECT
public class JPAPessoaFisicaDAO extends JPAAbstractDAO<PessoaFisicaBean>
implements PessoaFisicaDAO {
public PessoaFisicaBean getPessoaFisicaByCPF(String cpf) {
TypedQuery<PessoaFisicaBean> query = manager.createQuery(
"SELECT p from PessoaFisicaBean p where p.cpf = :cpf",
PessoaFisicaBean.class);
query.setParameter("cpf", cpf);
return query.getSingleResult();
}
// with others impl
}
OK
EJB Project add JPA Project in your classpath. OK
NO ERRORS. BUT in deploy:
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014544: No EJB found with interface of type 'br.com.processo.dao.PessoaFisicaDAO' for binding pacote.PessoaFisicaWS/dao
any idea?
EDIT:
When i add (DAO's and your impl) in my EJB Project (same package of WebService) ITS WORKS.
But i need separate in two projects.
Try to remove this annotation #EJB from dao because this is not an EJB.
Each module has its own classloader, so that the visibility of the class is limited to each module. You need create a jar with the interfaces and put in the lib directory of the EAR. See more in Class Loading in AS7, e.g.:
You need create a standard java project for store the business interfaces. The deployment assembly:
In the project explorere view you see:
It is pretty simple. The error is telling you to reference the Interface not the Implementation.
So make sure that "PessoaFisicaDAO" is an Interface with the #Remote or #LocalBean annotation
#EJB
private PessoaFisicaDAO dao;

Categories