Why the OSGI element cannot be recognized by the STS? - spring-tool-suite

The xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<bean id="demoBean"
class="org.spring.demo.DemoBean">
</bean>
<osgi:service ref="demoBean" interface="org.spring.demo.DemoInterface"></osgi:service>
</beans>
The SpringExplorer lists the "demoBean" node, but doesn't list the element of "osgi:service".
Other spring eclipse plugin should be installed?

Actually, this looks a little bit like a bug that I recently fixed in STS:
https://jira.spring.io/browse/INT-3674
So it may be worth trying updating your STS from nightly update site.
It could also be
another bug in STS causing it to miss beans that actually exist
a problem with the bean definition or schema causing the bean not to be properly defined.
You can try to distinguish between these two cases by making sure the beans you think should exist actually do exist at runtime when the application context is instantiated.
If the bean in fact exist and doesn't show up in STS model, then I'd consider that a bug in STS and you should consider filing a bug report. Otherwise it is another problem.

Related

Maven and Eclipse (Mars 4.5) JavaEE in conflict?

Problem began a few days ago, asked a question (Eclipse 4.5.1 jpa 2.1 facet error) but didn't get much response. In the mean time I've tracked down where the problem probably is (Maven workspace resolution setting) but have no clue about the solution. My IDS is Eclipse Mars 4.5 (newest version, downloaded and installed 2 days ago). The 'problem' project has a number of classes that extend #MappedSuperclasses (#MSC) from another project that is in the same workspace.
Here's what happens when Maven workspace resolution is:
ENABLED - (i) 'JPA Details' view functions properly, (ii) persistence.xml file opens properly (i.e. tabs at bottom show, etc), .. BUT (iii) adding #MSC to persistence.xml generates error "Class '[class]' cannot be resolved". Tried adding #MSC files to an orm.xml file, same result. Everything compiles (i.e. classes in problem project extend #MSC classes w/no problem).
DISABLED - (i) 'JPA Details' view no longer works, & (ii) persistence.xml opens only with basic xml editor, which generates many problem messages (including 'Target entity not defined') which suggest that Eclipse is no longer treating project as a qualified JPA project.
I'm really at 6's and 7's on this, would be grateful for some guidance. Is this one of those irritating false positives that needs to be suppressed? Thanks.
FWIW here's the text for the persistence.xml version:
persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"

Disable scanning of CDI beans in WAR

I have WAR package with CDI beans. Deployment of the package is very slow because every time during deployment the package is scanned for CDI beans. Is there any option to disable this process?
The correct way is to disable discovery in the beans.xml of the relevant archive:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="none">
</beans>
According to the CDI specification this removes the archive from the list of bean-archives.
I have a feeling that what you're looking for is more of a tool. As mentioned, Weld uses class scanning to find annotations. There are ways to speed this up. One that works pretty well is Jandex, an annotation processor that can be used at compile time to create an index (easier to read database) of your classes and annotations. This does dramatically boost deployment times.

guideline to generate boilerplate for xml like applicationContext?

I know that it's possible to generate this schema above by selecting all these options in STS(Spring Tool Suite):
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
The point is I want to generate beans schema in STS(without any copy-paste as I have done it). If anyone faced with that, please guide me! Because copy-paste is senseless.
In STS: Right click on some folder or package -> New -> Spring Bean Configuration File.
It will create empty xml with defined beans schema.

Liquibase autocompletion in eclipse (maven project)

I'm trying to have autocompletion for liquibase.
My project works fine with liquibase, but completion doesn't work.
I'm pretty sure it did work last week, after downloading javadoc/sources from liquibase.
Now, whenever I try to have eclipse autocomplete a changelog xml, I can see this:
Loading reference grammars (sleeping).
It then disappears, and autocompletion doesn't work.
Here is an example changeset header:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<!-- This changelog is used to validate that liquibase works -->
<changeSet id="1" author="majoros" >
</changeSet>
</databaseChangeLog>
EDIT: could very well be a proxy issue. I was briefly fully connected to the internet (don't ask...), and it's working now. Still, my coworkers should have it working, too (and I'd like to understand).
Eclipse should be able to use autocomplete on XML files that have a descriptor (or whatever it's called).
Liquibase's wiki has some examples for database change sets. These all include references to xsd files. These provide information on the structure of the XML.
Sample XML for 1.9:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd">
</databaseChangeLog>
Sample XML for 2.0:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
</databaseChangeLog>
Eclipse fetches the xsd files from the web so an Internet connection is required. If you're behind a proxy you have to configure Eclipse to use a proxy. This might explain why it didn't work at first.
To configure a proxy in Eclipse:
Window > Preferences > General > Network connections

JBoss 5 AS and EJB3 bean injection from servlets?

It was my understanding that JBossAS 5.x supported EJB3 bean injection in servlets with the #EJB3 annotation. I'm using the default configuration for JBossAS 5.0.1.GA and it's not working. I've added the mappedName argument to the #EJB annotation with the session beans JNDI name, and it just doesn't do anything. No apparent errors, the bean is just never injected.
The session beans are in the ejb-jar, the servlets in a war, everything is packaged in an ear. Manual JNDI lookups work just fine. Any ideas?
This may happen if your web.xml points to an older version of the spec. Ideally, it should be something like
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
This link may help a little too.
You should also check the jar file needed for EJB3 deployment in the classpath.JAr file is jboss-ejb3-ext-api.jar.